1

I am using simple-salesforce to read metadata from some CustomObjects: metadata = _sf.mdapi.CustomObject.read(sf_object_name)

This generally works, EXCEPT for a number of Picklist fields: the options return as a named ValueSet instead of a list of options (see below).

How can I get the actual Picklist options? Do I need to call a different API method with the ValueSetName (ex. Student_Challenge_Experience_Homesick)?

    {
      'fullName': 'Experiencing_Homesickness__c',
      ...
      ...
      'type': 'Picklist',
      'unique': None,
      'valueSet': {
        'controllingField': None,
        'restricted': True,
        'valueSetDefinition': None,
        'valueSetName': 'Student_Challenge_Experience_Homesick',
        'valueSettings': [
          
        ]
      },
      'visibleLines': None,
      'writeRequiresMasterRead': None
    },

For completeness' sake: some fields DO return a list of picklist values with their label & value:

      'valueSet': {
        'controllingField': None,
        'restricted': None,
        'valueSetDefinition': {
          'sorted': False,
          'value': [
            {
              'fullName': '3',
              'color': None,
              'default': False,
              'description': None,
              'isActive': None,
              'label': '3'
            },
            {
              'fullName': '4',
              'color': None,
              'default': False,
              'description': None,
              'isActive': None,
              'label': '4'
            },
            {
              'fullName': '5+',
              'color': None,
              'default': False,
              'description': None,
              'isActive': None,
              'label': '5+'
            }
          ]
        },
        'valueSetName': None,
        'valueSettings': [
          
        ]
      },
      'visibleLines': None,
      'writeRequiresMasterRead': None
    },
ezeYaniv
  • 412
  • 5
  • 18

1 Answers1

1

Sounds like a global picklist (picklist definition that can be reused, even on different objects, maintained in 1 place and if you add a new value - it adds everywhere). https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_globalvalueset.htm

See if you can pull it with _sf.mdapi.GlobalValueSet.read('Student_Challenge_Experience_Homesick')

Or alternative approach is to query the picklists: https://stackoverflow.com/a/76840387/313628

eyescream
  • 18,088
  • 2
  • 34
  • 46
  • thanks, that's excellent! Does the job. Out of curiosity, would there be any way to do that in a bulk way for a number of these valuesets? – ezeYaniv Aug 11 '23 at 20:58
  • In simple Salesforce? No idea. Try with asterisk maybe (wildcard)? Metadata API supports * when fetching these with package.xml so could work – eyescream Aug 11 '23 at 22:04