You need to sign in to do that
Don't have an account?
Jerun Jose
Update picklist values using Metadata API
Hi,
Can someone help me out with Metadata API ? I need to figure out a way to change values for a picklist field using apex. I thought that an update() call using the Metadata API should be the right direction, but having a hard time putting together the format of the request.
Also, can we do picklist value changes in Production using the update() call? Based on the post at
Hi Jerun Jose,
You can use following code if you are calling salesforce from JAVA.
public void setPicklistValues() { // Create a picklist Picklist expenseStatus = new Picklist(); PicklistValue unsubmitted = new PicklistValue(); unsubmitted.setFullName("Unsubmitted"); PicklistValue submitted = new PicklistValue(); submitted.setFullName("Submitted"); PicklistValue approved = new PicklistValue(); approved.setFullName("Approved"); 126 Metadata Types Picklist (Including Dependent Picklist) PicklistValue rejected = new PicklistValue(); rejected.setFullName("Rejected"); expenseStatus.setPicklistValues(new PicklistValue[]{unsubmitted, submitted, approved, rejected}); CustomField expenseStatusField = new CustomField(); expenseStatusField.setFullName("ExpenseReport__c.ExpenseStatus__c"); expenseStatusField.setLabel("Expense Report Status"); expenseStatusField.setType(FieldType.Picklist); expenseStatusField.setPicklist(expenseStatus); try { UpdateMetadata ut = new UpdateMetadata(); // Set CurrentName of existing picklist field ut.setCurrentName("ExpenseReport__c.ExpenseStatus__c"); ut.setMetadata(expenseStatusField); AsyncResult[] asyncResultsupdate = metadataConnection.update(newUpdateMetadata[] {ut}); } catch (ConnectionException ce) { ce.printStackTrace(); } }
In the above code we are updating the field ExpenseStatus__c of Object ExpenseReport__c.
If you are using Apex method then i have already posted the code on this discussion board.
http://boards.developerforce.com/t5/Apex-Code-Development/Add-new-Picklist-value-with-trigger/m-p/585055#M107031
I am not able to find the method setPicklist(expenseStatus) as you used in the below line.
expenseStatusField.setPicklist(expenseStatus);
Is it something got changed in the latest releases. Appreciate your help.