+ Start a Discussion
Apex LearnerApex Learner 

Updating Pick list values via metadata API need help

hi guys i have woring on METADATA Api 


and i have successfully create soap envelope to add new picklist value in picklist field


<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:met="http://soap.sforce.com/2006/04/metadata">
      <update xmlns="http://soap.sforce.com/2006/04/metadata">
     <!--Zero or more repetitions:-->
      <UpdateMetadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="customfield">
		      <metadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CustomField">

 Now issues I am facing , is

Is there any way to update / edit any particular picklist value ???


e.g , Object : Lead , field : number__c, type : picklist , picklist values : new , old 


any way i can edit "new " to "new_value" via meta data API .


Thanks to soap and metadata api developers in advance 





I think what the way you are using to create the fields(copy the fields) in meta data API. it also worked for delete and edit the picklist value in metadata Api. 

Apex LearnerApex Learner

Hi .


Thanks for reply 



But .No actually ..

metadata Api does not support deleting picklist value . for sure 


i just could not find any method to edit any particular picklist value 

Apex LearnerApex Learner

I am just Posting updated verison with controlling field 

  but still no answer on updaiung pisklist value ::: :(

public with sharing class soap_envelope1 {
	public void update_picklist (string session_id, string client_id, string current_object , string current_field, string new_value, string is_custom, string label, string controlling_field, string controlling_field_value){
    string SoapBody = '<?xml version="1.0" encoding="UTF-8"?>';
    SoapBody += '<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">';
    SoapBody += '<S:Header>';
     SoapBody += '<SessionHeader xmlns="http://soap.sforce.com/2006/04/metadata"> ';
     SoapBody += '<sessionId>'+session_id+'</sessionId>';
     SoapBody += '</SessionHeader>';
     SoapBody += '<CallOptions xmlns="http://soap.sforce.com/2006/04/metadata">';
     SoapBody += '<client>'+client_id+'</client>';
     SoapBody += '</CallOptions>';
     SoapBody += '</S:Header>';
     SoapBody += '<S:Body>';
      SoapBody += '<update xmlns="http://soap.sforce.com/2006/04/metadata">';
      SoapBody += '<!--Zero or more repetitions:-->';
      SoapBody += '<UpdateMetadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Customfield">';
      SoapBody += '<currentName>'+current_object+'.'+current_field+'</currentName>';          
      SoapBody += '<metadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CustomField">';
      SoapBody += '<!--Optional:-->';
      SoapBody += '<fullName>'+current_object+'.'+current_field+'</fullName>';
   if (is_custom =='true') 
      SoapBody += '<label>'+label+'</label>';
      SoapBody += '<picklist>';
  if(controlling_field != '-none-')
       soapbody += '<controllingField>'+controlling_field+'</controllingField>';  
         SoapBody += '<picklistValues>';
         SoapBody += '<fullName>'+new_value+'</fullName>';
            if (controlling_field_value != '-none-')
              soapbody+= '<controllingFieldValues>'+controlling_field_value+'</controllingFieldValues>';
          SoapBody += '</picklistValues>';
          SoapBody += '<sorted>false</sorted>';
        SoapBody += '</picklist>';
        SoapBody += '<type>Picklist</type>';
           SoapBody += '</metadata>';
          SoapBody += '</UpdateMetadata>';
       SoapBody += '</update>';
      SoapBody += '</S:Body>';
    SoapBody += '</S:Envelope>';
    system.debug('soap envelope============================================='+SoapBody );
       HttpRequest req= new HttpRequest(); 
            req.setHeader('content-type', 'text/xml; charset=utf-8');  
            req.setHeader('SOAPAction', 'https://ap1-api.salesforce.com/services/Soap/m/25.0' );
            Http ht = new Http(); 
            Httpresponse response = new Httpresponse();
            response = ht.send(req);
           // return 'success';





I've been trying to use the Force.com ANT migration tool to delete picklist values but I haven't had any success.


The only way to delete a picklist value is by manual configuration.


I think the option to update or delete an existing picklist value is not available because of data integrity problem that comes along with deleting an existing picklist value.


If you rename or delete an existing picklist value you will also have to address any records that references the deleted and renamed picklist value.