Giter Site home page Giter Site logo

Comments (6)

mohit-address avatar mohit-address commented on July 30, 2024
 
<UpdateMetadata>
    <currentName>lead.picklist1__c</currentName>
        <metadata xsi:type="CustomField">
            <fullName>lead.dependet_picklist__c</fullName>
            <label>dependet_picklist</label>
                <picklist>
                    <controllingField>lead.picklist__c</controllingField>
//-----------------------------//   <picklistValues xsi:type="PicklistValue">
                            <fullName>first_dependent</fullName>
                            <controllingFieldValues>first</controllingFieldValues>
                            <default>false</default>
                        </picklistValues>
                        <sorted>false</sorted>
                </picklist>
            <type>Picklist</type>
        </metadata
</UpdateMetadata>'

check long line , it should not add xsi:picklistvalue , as per the metadata api document
I suppose ..
What you think ? any issue here . or I am missing somthing

from apex-mdapi.

afawcett avatar afawcett commented on July 30, 2024

Maybe this is the issue try, first_dependent.type = null; this will stop it sending the xsi:type. You don't show what the error is though, have you checked that? If you dump out the ID returned via results[0].id you can then issue some Anonymous Apex calls to checkAsync to get the result and error message. Unless you have implemented in your page an actionPoller to do this for you.

from apex-mdapi.

mohit-address avatar mohit-address commented on July 30, 2024

Here is the example for Creating picklist field , with controlling field , and controlling field values


  public static void createPicklistField()
    {
        MetadataService.MetadataPort service = createService();     
        MetadataService.CustomField customField = new MetadataService.CustomField();
            customField.fullName = 'lead.dependent_picklist__c';
            customField.label = 'Dependent Picklist';
            customField.type_x = 'Picklist';
            
        
        metadataservice.Picklist pt = new metadataservice.Picklist(); // creat picklist metadata
            pt.sorted= false;
            pt.controllingField = 'Controlling_Picklist__c'; // Define controlling field only name . not object name, if you are creating Dependent field , else dont include line : if field dependency doesnot exist , it will create new one
        
        metadataservice.PicklistValue one = new metadataservice.PicklistValue(); // create picklist values metadata
            one.fullName= 'Dependent 0';
            one.default_x=false ;
            one.controllingFieldValues = new list  {'Control Odd number'};  // assign controlling field values
           
        metadataservice.PicklistValue two = new metadataservice.PicklistValue();
            two.fullName= 'Dependent 1';
            two.default_x=false ;
            two.controllingFieldValues = new list  {'Control Odd number','Control Even number'}; // assign controlling field values
            
        pt.picklistValues = new list{one,two}; // assign picklist values
            customField.picklist = pt ;                                       // assign Picklist
        MetadataService.AsyncResult[] results = service.create (new List { customField });
      
    } 

and here is the code to update picklist field


 public static void UpdatePicklistField()
    {
         MetadataService.MetadataPort service = createService();
         MetadataService.CustomField customField = new MetadataService.CustomField(); 
            customField.fullName = 'lead.dependent_picklist__c';
            customField.label = 'Dependent Picklist';
            customField.type_x = 'Picklist'; 
            
        metadataservice.Picklist pt = new metadataservice.Picklist();
            pt.sorted= false;
            pt.controllingField= 'Controlling_Picklist__c'; //***** name of controlling field . if picklist has contrlloing field , this must be asssigned . else field dependency will be deleted
            
                metadataservice.PicklistValue first_dependent = new metadataservice.PicklistValue();
                 first_dependent.fullName= 'Dependent 2'; 
                 first_dependent.default_x=false ;
                 first_dependent.controllingFieldValues = new list {'Control Even number'};  // list of names of controlling field Picklist value . dont put this line , if you dont want any controlling picklist value
           pt.picklistValues = new list{first_dependent};
         customField.picklist = pt ;
       
       
       MetadataService.UpdateMetadata ut = new MetadataService.UpdateMetadata();
            ut.currentName='lead.dependent_picklist__c';
            ut.metadata= customField;
       MetadataService.AsyncResult[] results = service.updateMetadata(new List {ut});
         
    }

from apex-mdapi.

afawcett avatar afawcett commented on July 30, 2024

Thanks for posting your solution code here! I've updated the example Apex class with it. Sounds like you had fun (?) working it out! If you can, you should blog more generally about what it is your doing. From the looks of this code, looks kinda interesting! ;-)

from apex-mdapi.

mohit-address avatar mohit-address commented on July 30, 2024

Hi ,
Thanks for the encouragement .. really appreciated .
YEs , I m having lot of fun with it . working on metadata api inside sfdc , is opening whole new scope of possibilities .
thanks for that ..
But I recently hit an bump with record types .
i also opened one issue here with name : -- Request : need some help on record type , Picklist field Describe call

I dont know whether you had time to look at it , but if you can just check it out once , that would be great ,
--its shows limitation on metadata api from apex , or metadata APi in general ,
I also raised same question with salesforce.com , but haven't heard back from them . :(

from apex-mdapi.

afawcett avatar afawcett commented on July 30, 2024

That is frustrating. I think I have answered this question though, Issue 4? #4

from apex-mdapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.