Comments (6)
<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.
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.
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.
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.
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.
That is frustrating. I think I have answered this question though, Issue 4? #4
from apex-mdapi.
Related Issues (20)
- Help article to use named credentials with wrapper has been removed HOT 1
- Generate an Apex from WSDL
- GlobalValueSetTranslation HOT 2
- Update search layout task, event, activity HOT 1
- System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element customizeSetup
- Apex Wrapper Metadata API Takes Time to Reflect the Change
- Can't create in production org
- Can't create a sharing rule HOT 2
- GlobalValueSetTranslation
- Can we create ApexClass natively? Any Example? HOT 1
- UserInfo.getSessionId() makes this unusable in packaged code HOT 2
- How do we update multiple profiles at once?
- LightningComponentBundle (LWC): reading/creating/updating
- Creating Apex Trigger
- Creating a MultiPicklist HOT 2
- System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element includeRecordsOwnedByAll
- How To get Picklist Value according to record type for a custom object HOT 3
- Can anyone suggest on how to read the flexipage? HOT 7
- Issue retrieving layout metadata for object via Metadata API HOT 1
- Row Lock Error - Updating the Picklist values in the Customer field and RecordTypes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apex-mdapi.