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.

  • 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 '18 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 '18 at 13:26
2

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

  • 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 '18 at 13:23
  • @JustinF You need to make SOQL Like SELECT ID,TableEnumOrId,DeveloperName from CustomField WHERE DeveloperName = 'Activity_Sector' – Tushar Sharma Aug 27 '18 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 '18 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 '18 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. – Tushar Sharma Aug 28 '18 at 4:17

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.