I'm working on a small application that uses the metadata api to make some structural changes on some default objects. One of the changes is adding some picklist values to the Contract's status field. This is the code that should update it:

//MetaDataService is the apex2wsdl class generated from the metadata api wsdl.
MetaDataService.Picklist pl = new MetaDataService.Picklist();
pl.sorted = false;
pl.picklistValues = new List<MetaDataService.PicklistValue>();
MetaDataService.PicklistValue pv = new MetaDataService.PicklistValue();
pv.fullName = 'My new picklist value';
pv.default_x = false;

MetaDataService.CustomField customField = new MetaDataService.CustomField();
customField.fullName = 'Contract.Status';
//customField.label = 'Type';
customField.type_x = 'Picklist';
customField.picklist = pl;

MetaDataService.UpdateMetaData umd = new MetaDataService.UpdateMetaData();
umd.metaData = customField;
umd.currentName = 'Contract.Status';

MetaDataService.MetadataPort service = MetaDataController.createService();
MetaDataService.AsyncResult[] results = service.updateMetaData(new MetaDataService.UpdateMetaData[] { umd });

The response that I'm getting says that Contract.Status is not a picklist field. Is it maybe because I use the CustomField object? If so, what is the correct way to do this?


The Contract Status field is a process picklist, in lines with Opportunity Stage and Lead Status. These fields are tied to specific object processes and have extra metadata, i.e. whether the contract status is Activated or Draft.

While you can query the available values in the ContractStatus object it does not appear that their is currently any support for manipulating the valid values for this picklist and your only option for automating the deployment would be to use a web scripting tool to automate the button clicks to create the new value. You might also consider creating an idea to add this support.

However, you do have the ability to update the which processes use which values via Contract's business process attributes.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.