7

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 ...
         }
       }
  }
2

1 Answer 1

6

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .