function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dave The RaveDave The Rave 

Field IDs per Object using SOQL query

Hi All,

Using SOQL query below which shows all field IDs for all custom fields.

Select Id, DeveloperName from CustomField

How can I limit this SOQL query to only show Field IDs for a specific object? for example to case object?

Thanks,

Dave the Rave
Best Answer chosen by Dave The Rave
SwethaSwetha (Salesforce Developers) 
HI Dave,
You can try this and see if it fetches the desired result
Select Id, DeveloperName from CustomField where TableEnumOrId='Case'
 
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you

All Answers

SwethaSwetha (Salesforce Developers) 
HI Dave,
You can try this and see if it fetches the desired result
Select Id, DeveloperName from CustomField where TableEnumOrId='Case'
 
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
This was selected as the best answer
AnudeepAnudeep (Salesforce Developers) 
There isn't any field in the in CustomField that can filter on specific object. You should try ToolingAPI

See SOQL in the following example
// Constructs the Tooling API wrapper (default constructor uses user session Id)
ToolingAPI toolingAPI = new ToolingAPI();
 
// Query CustomObject object by DeveloperName (note no __c suffix required)
List<ToolingAPI.CustomObject> customObjects = (List<ToolingAPI.CustomObject>)
     toolingAPI.query('Select Id, DeveloperName, NamespacePrefix From CustomObject Where DeveloperName = \'Test\'').records;
 
// Query CustomField object by TableEnumOrId (use CustomObject Id not name for Custom Objects)
ToolingAPI.CustomObject customObject = customObjects[0];
Id customObjectId = customObject.Id;
List<ToolingAPI.CustomField> customFields = (List<ToolingAPI.CustomField>)
     toolingAPI.query('Select Id, DeveloperName, NamespacePrefix, TableEnumOrId From CustomField Where TableEnumOrId = \'' + customObjectId + '\'').records;
 
// Dump field names (reapply the __c suffix) and their Id's
System.debug(customObject.DeveloperName + '__c : ' + customObject.Id);
for(ToolingAPI.CustomField customField : customFields)
     System.debug(
          customObject.DeveloperName + '__c.' +
          customField.DeveloperName + '__c : ' +
          customField.Id);


 
NB AgencyNB Agency
thank you
Nb Agency (https://nb-agency.com/)