function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ankit Singh 6Ankit Singh 6 

Updating picklist value through metadata api throwing error 'Concurrent modification from setup pages'

Hi

I am trying to update picklist value for leadsource through metadata api but not sure why getting 'Concurrent modification from setup pages' error. 
Below is my code :
private bool UpdatePicklist(string sfObject, string picklistName, List<string> picklistValues)
        {
            List<string> extraPickList = new List<string>();
            if (_ms == null)
                GetMetaDataService();
            DescribeSObjectResult sr = _sf.describeSObject(sfObject);
            if (sr == null || sr.fields == null || sr.fields.Length == 0)
            {
                _log.Info("Error occured : sf object description is null");
                return false;
            }

            foreach (Field field in sr.fields)
            {
                if (!(field.type == fieldType.picklist && field.name == picklistName))
                    continue;
                foreach (PicklistEntry entry in field.picklistValues)
                {
                    if (!picklistValues.Contains(entry.value))
                    {
                        extraPickList.Add(entry.value);
                    }

                }
                if (extraPickList.Count > 0)
                {
                    extraPickList.AddRange(picklistValues);
                    CustomField co = new CustomField();
                    co.fullName = sfObject + "." + picklistName;
                    co.type = (SfApi.FieldType)Enum.Parse(typeof(SfApi.FieldType), "Picklist");
                    co.picklist = new Picklist();
                    co.picklist.sorted = true;
                    List<PicklistValue> picklistArray = new List<PicklistValue>();
                    foreach (string picklistValue in extraPickList)
                    {
                        PicklistValue pick = new PicklistValue();
                        pick.fullName = picklistValue;
                        // setting default value
                        if (picklistValue == "Other")
                            pick.@default = true;
                        picklistArray.Add(pick);
                    }
                    co.picklist.picklistValues = picklistArray.ToArray();
                    Metadata[] m = new Metadata[] { co };
                    UpdateMetadata um = new UpdateMetadata();
                    um.metadata = m[0];
                    UpdateMetadata[] uma = new UpdateMetadata[] { um };
                    AsyncResult r = _ms.update(uma)[0];
                    //AsyncResult r = _ms.create(m)[0];
                    while (!r.done)
                    {
                        System.Threading.Thread.Sleep(10 * 1000);
                        r = _ms.checkStatus(new string[] { r.id })[0];
                        _log.Info("Still On");
                    }
                    if (r.state == AsyncRequestState.Error)
                    {
                        _log.Info("Error : " + r.statusCode + " " + r.message);
                        return false;
                    }
                    else
                    {
                        _log.Info("Picklist successfully recreated");
                        return true;
                    }
                }
                else
                    return true;
                break;
            }
            return false;
        }

Please let me know the solution for this, tried many things but no success.
ShashForceShashForce
Hi Ankit,

This error is usually seen, if there is a dependant picklist field that has been modified in production after the last Sandbox Refresh, or if the target org had a picklist field that was modified later than the source and had different values. All the values have to be exactly the same. If not, they have to be manually matched to be the same.

Thanks,
Shashank