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
CP_PDCP_PD 

Inactive Picklist values

I am updating a picklist value through API 37.0 using .net c#
It works fine, but if the user select another value in the picklist, the value I added is gone.

I can't find a property to save the value.

any suggestions ?
AshlekhAshlekh
Hi,

When you are updating the value through the api then the value override the current value but that value is not a part of picklist values which is defined in the system.

Next time when user see the option to update the value then only those option will be available which is defined for that picklist value in system.

-Thanks
Ashlekh Gera
CP_PDCP_PD
Hi Ashlekh!
Thanks for your replay :-)

I'm not familiar with Salesforce at all, but:

Are you telling me, that it is not possible to update the list of values in a picklist - doing this througt the API.
 
Sergio AlcocerSergio Alcocer
You would need to use the metadata api for that (to change the pre-defined possible values of a picklist)
CP_PDCP_PD
Hi Sergio
I am using the metadata api, and the picklist value will be updated and selected. But the value is inactive (according to my salesforce colleague), and when the value is changed in the picklist, it dissapear, and can't be choosen any more.
(see my code below:)
public void ChangePicklist(PICKLIST_ACTIONS plAction, string tableName, string fieldName, string picklistValue) {
            // Load describe info for the object.
            DescribeSObjectResult dor = binding.describeSObject(tableName);

            if (dor != null) {
                Field[] fields = dor.fields;
                foreach (Field field in fields) {
                    if (field.name == fieldName) {
                        // Get the array of existing picklist entries.
                        sforce.PicklistEntry[] picklistEntries = field.picklistValues;
                        // Recreate the entire list of existing picklist values...
                        List<PicklistValue> pVals = new List<PicklistValue>();
                        PicklistValue pVal;
                        foreach (sforce.PicklistEntry picklistEntry in picklistEntries) {
                            bool updatePl = true;
                            if ((plAction == PICKLIST_ACTIONS.Delete) & (picklistEntry.value == picklistValue))
                                updatePl = false;
                            if (updatePl) {
                                pVal = new PicklistValue();
                                pVal.@default = picklistEntry.defaultValue;
                                if (picklistEntry.label != null)
                                    pVal.fullName = picklistEntry.label;
                                else
                                    pVal.fullName = picklistEntry.value;
                                pVals.Add(pVal);
                            }
                        }
                        if (plAction == PICKLIST_ACTIONS.Create) {
                            // Add the NEW value...
                            pVal = new PicklistValue();
                            pVal.fullName = picklistValue;
                            pVals.Add(pVal);
                        }
                        // Save the values to a new picklist.
                        Picklist pList = new Picklist();
                        pList.picklistValues = pVals.ToArray();
                        CustomField picklistField = new CustomField();
                        picklistField.fullName = tableName + "." + fieldName;
                        picklistField.description = fieldName;
                        //picklistField.label = field.label;
                        picklistField.type = FieldType.Picklist;
                        //picklistField. <-- looking for a property, so the value is not inactive !!!!!!!!!!!!!!! 
                        picklistField.typeSpecified = true;
                        picklistField.picklist = pList;
                        picklistField.inlineHelpText = field.inlineHelpText;

                        MetadataService mds = new MetadataService();
                        mds.SessionHeaderValue = new metadata.SessionHeader();
                        mds.SessionHeaderValue.sessionId = sessionID;
                        mds.Url = metadataURL;

                        metadata.SaveResult[] result = mds.updateMetadata(new Metadata[] { picklistField });
                    }
                }
            }
        }

 
Sergio AlcocerSergio Alcocer
Not even sure because I hardly ever use the metadata api, but maybe you need to assign the picklist values to the right recordTypes so they get displayed.

Kind regards.
ankita varma 3ankita varma 3
I have similar issue, but I want to show a picklist value which is uploaded by data loader and is not in the active picklist.
Regards,
Ankita