5

I'm using Partner API to describe salesforce schema. For some reason, in picklist fields I only see the active values (although there's a field "getActive()")

Is this a limitation or am I doing something wrong? how can I get the Inactive picklist values?

My code is along the lines of:

    obj = partnerConnection.describeSObject("Lead");
    for (Field f : obj.fields) {

       if (FieldType.picklist.equals(f.getType()) || FieldType.multipicklist.equals(f.getType())) {
         for (PicklistEntry e : f.getPicklistValues())  {
         if (e.getActive()) {
            // This is OK       
         }
         else
         {
            // This part is not reached, seems Inactive values are not returned ...
         }
       }
  }
  • 1
    Shouldn't you be calling the isActive() method? Im not sure what getActive() is? Take a look at the PicklistEntry class. – TSmith Nov 29 '16 at 14:22
4

I believe this to be a current limitation of the API for picklist fields.

I tried as well to get field metadata for a deactivated picklist value. It didn't come back, even though there is an active property.

It appears the same problem exists in the REST API with the /describe resource or a tooling API query against FieldDefinition - Obtain the complete list of Picklist values via REST API (both active and inactive)

The limitation even goes to the Apex class. E.g. the following won't return inactive picklist values:

Schema.DescribeFieldResult F = Account.Rating.getDescribe();
List<Schema.PicklistEntry> P = F.getPicklistValues();
System.debug(P);

The Metadata API used to expose a Picklist Metadata type, but for v38.0 and later it switched to ValueSet.

I think most of the problems stem from Picklist in the older Metadata API not exposing a IsActive property. However, CustomValue, that is used from v38.0 onwards does have a isActive.

Update: I thought that the new Metadata API StandardValueSet would have exposed the isActive field. However, with the following Metadata API package it doesn't come back.

package.xml for the Account.Rating picklist.

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>AccountRating</members>
        <name>StandardValueSet</name>
    </types>
    <version>38.0</version>
</Package>

Response \standardValueSets\AccountRating.standardValueSet

<?xml version="1.0" encoding="UTF-8"?>
<StandardValueSet xmlns="http://soap.sforce.com/2006/04/metadata">
    <sorted>false</sorted>
    <standardValue>
        <fullName>Hot</fullName>
        <default>false</default>
    </standardValue>
    <standardValue>
        <fullName>Warm</fullName>
        <default>false</default>
    </standardValue>
    <standardValue>
        <fullName>Cold</fullName>
        <default>false</default>
    </standardValue>
</StandardValueSet>

Deactived Picklist Value

  • Thank you, this supports what I believe as well. Is there some other API which does expose this? – Yossi Vainshtein Dec 1 '16 at 9:36
  • @YossiVainshtein Not that I can find. All the API's seem to exclude inactive picklist values. – Daniel Ballinger Dec 1 '16 at 23:47
0

Thank you for the post.

EDIT: Seems removing a picklist value in the API DOES make it inactive, I just had to remove all occurrences of that value from that specific object.


I have tried making a picklist value inactive via API, by removing the value directly from the field. But after saving the object file the value is still available and active. Seems that it can only be deactivated in the UI.

  • 2
    This is correct, but my question was not how to deactivate a value in API, but rather how to get values which were inactivated (in the UI) via metadata – Yossi Vainshtein Jan 4 '17 at 8:37
  • Did you get the solution to your query? if so please share your ideas – Dinesh Oct 4 at 6:54

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.