1

I would like to query all picklist fields on a specific object, along with their associated unique Salesforce IDs (I'll be loading these as custom metadata types). I don't need the picklist values, just the field API name & the 18 character ID for that field.

How can I get this data? I thought about maybe using workbench, but I'm not sure what the query should be.

Thanks in advance.

2
  • you can get the fields and incase of picklists the values with the rest api describe calls. as far as i aware the identifier for fields is the api name and not an id
    – Gilhil
    Aug 27, 2018 at 13:12
  • @Gilhil yes, I'm asking what the query to the rest API should look like. Seems like a SOQL query will be the easiest. And yes, every piece of metadata in Salesforce comes with an ID. I need to get the API name and ID for all picklist fields on an Object.
    – JustinF
    Aug 27, 2018 at 13:26

2 Answers 2

3

You can easily do this using Tooling API. Just run this query in developer console Query Editor and check the tooling API checkbox. You will get the result.

SELECT ID,TableEnumOrId,DeveloperName from CustomField

enter image description here

5
  • Thanks, this is very helpful, but haven't got it quite right yet... If I execute this: SELECT ID,TableEnumOrId,DeveloperName from Innovation__c.Activity_Sector__c Then I get this error: First SObject of the FROM statement must be a valid SObject type.
    – JustinF
    Aug 27, 2018 at 13:23
  • @JustinF You need to make SOQL Like SELECT ID,TableEnumOrId,DeveloperName from CustomField WHERE DeveloperName = 'Activity_Sector' Aug 27, 2018 at 13:33
  • I'm not sure if you mean "CustomObject" instead of "CustomField", since to my knowledge you cannot SELECT FROM a CustomField. Either way, that query does not work. Here is the query I just tried: SELECT ID,TableEnumOrId,DeveloperName from Innovation__c WHERE DeveloperName = 'Activity_Sector'. I got this error: No such column 'TableEnumOrId' on entity 'Innovation__c'.
    – JustinF
    Aug 27, 2018 at 13:41
  • Let me clarify things... I want to Select the API Name and ID of all picklist fields on the object Innovation__c. So ideally, I'd like to have query that looks something like this: SELECT Name, ID from AllPicklistFields where sObject = Innovation__c AND type = "picklist". Obviously I know that's an invalid query, but what would a valid query for that be?
    – JustinF
    Aug 27, 2018 at 13:43
  • @JustinF You are querying metedata so this query will never work as you need field Id. Use my query once and see what result you get and check the checkbox as well. Aug 28, 2018 at 4:17
0

To get field Ids ...

For standard objects (using Tooling API)

SELECT Id, DeveloperName WHERE TableEnumOrId = 'Account'

For custom objects (Using Tooling API)

  • First you need to get the TableOrEnumId of the custom object

    SELECT Id, DeveloperName FROM CustomObject WHERE DeveloperName = `My_Custom_Object`
    

Note you don't use __c per CustomObject doc

  • Then use the Id in this query

    SELECT Id, DeveloperName FROM CustomField WHERE TableEnumOrId = 'idFromCustomObjectQuery'
    

You must log in to answer this question.

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