I'm trying to update the picklist value of a custom field in sobj 'Contacts' via the usage of metadata API. So far I was able to:
- Generate the apex class form WSDL
- fix the issue with session id
- Create trigger (user update) to call the class for updating the picklist via metadata API
so when I update the user I could see the session id generated (via debug) and the trigger is called but had an error as below:
FATAL_ERROR|System.CalloutException: IO Exception: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = https://XXXX.salesforce.com/services/Soap/m/33.0
To fix this i followed the error info and maintained the remote-site setting as:
Following this i see another error after the trigger call:
Web service callout failed: WebService returned a SOAP Fault: Must specify a {http://www.w3.org/2001/XMLSchema-instance}type attribute value for the {http://soap.sforce.com/2006/04/metadata}metadata element faultcode=soapenv:Client faultactor=
My class is:
public static void UpdatePicklistField(String sessionId)
{
MetadataAPIService.MetadataPort service = createService();
service.SessionHeader.sessionId = sessionId;
MetadataAPIService.CustomField customField = new MetadataAPIService.CustomField();
customField.fullName = 'Contact.Test__c';
customField.label = 'Sales Owner';
customField.type_x = 'Picklist';
metadataAPIservice.Picklist sown = new metadataAPIservice.Picklist();
sown.sorted= false;
metadataAPIservice.PicklistValue pval = new metadataAPIservice.PicklistValue();
pval.fullName= 'SHP Picked';
pval.default_x=false ;
sown.picklistValues = new List<MetadataAPIService.PicklistValue>{pval};
customField.picklist = sown ;
List<MetadataAPIService.SaveResult> results =
service.updateMetadata(
new MetadataAPIService.Metadata[] {
CustomField
}
);
handleSaveResults(results[0]);
}
Any inputs on what needs to be done here to fix the errors and see the metadata api working to update the picklist values?