+ Start a Discussion
StellarStellar 

How could I get field IDs?

Hi,

Could anyone please indicate if it is possible to retrieve field IDs in bulk or through API?

I only know one method that we can find them on the html pages, which are normally settled for standard fields or 15-character identifier for custom fields. Is there a way to capture them in whole or programmatically? 

Any idea on this would be great for us. Thank you very much!

Best regards,
Stellar
 
Best Answer chosen by Stellar
Pankaj_GanwaniPankaj_Ganwani
Hi Stellar,

User-added image

Just use below mentioned SOQL to query editor of developer console by making 'Toolin API' checkbox checked: 

select Id from CustomField

 

All Answers

Pankaj_GanwaniPankaj_Ganwani
Hi Stellar,

User-added image

Just use below mentioned SOQL to query editor of developer console by making 'Toolin API' checkbox checked: 

select Id from CustomField

 
This was selected as the best answer
StellarStellar
Hi Pankaj,

Thank you very much. It seems working! Could you also instruct me how to retrieve IDs for standard fields?
In addition, does this mean all IDs for custom fields have been retrieved?

I am so grateful for your response.

Best regards,
Stellar 
Pankaj_GanwaniPankaj_Ganwani
Hi Stellar,

The api names of the standard fields are treated as Ids for themselves. Standard fields do not have alphanumeric Id format like custom fields have. To retrieve the api names of all the standard fields you will have to use below mentioned code:
 
List<string> SObjectList = new List<string>();

for(Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values()){
   String name = objTyp.getDescribe().getName();
   // Exclude all the unwanted Sobjects e.g. History, Share etc..

 if(!name.containsignorecase('history') && !name.containsignorecase('tag')&&
    !name.containsignorecase('share') && !name.containsignorecase('feed')){      
      SobjectList.add(name);
  }
   // Insert into your custom settings
  }

 Map<String, Set<String>> SObjectFieldsMap = new Map<string,Set<string>> ();
      Map<String, Schema.SObjectType> GlobalDescribe = new Map<String, Schema.SObjectType>();
      // Get the Global Describe which contains details for all objects
      GlobalDescribe =Schema.getGlobalDescribe();

      // Now we loop through our pre-compiled list of SObjects and get the describes for it
      for(String sObj:SObjectList)
      {
       // Populate the Map, with Sobject => list of fields
       if(SObjectFieldsMap.get(Sobj)==null && GlobalDescribe.get(sObj)!=null)
        SObjectFieldsMap.put(sObj,new Set<string>());

        if(SObjectFieldsMap.get(sObj)!=null) // Some Objects may not have Describes 
        SObjectFieldsMap.get(sObj).addAll(GlobalDescribe.get(sObj).getDescribe().fields.getMap().keyset());
      }

 
StellarStellar
Hi Pankaj,

Thanks a lot for your answer, but as I am not good at this. I need to have my team member to try the code later. 

There is one more request: could you tell me whether it is possible to get the whole form of what can be retrieved? The problem is that even though we found the ids with your help, we cannot match them with the field names. 

Is there a complete form or where I can get the resource from? 

Many thanks,
Stellar
Pankaj_GanwaniPankaj_Ganwani
Hi Stellar,

Yes, you can also retrieve the API names of the fields using below mentioned query from developer console:

select Id, DeveloperName from CustomField

Here DeveloperName gives field api name

Thanks,
Pankaj
StellarStellar
Hi Pankaj,

Thank you so much. But I'm sorry to further bother you by asking where we should put the code you mentioned to retrieve the api names of all the standard fields. We tried it, but error showed up. Since we are quite new to Salesforce, I don't think we tried it in the right place.

Could you indicate in further details how we should proceed? 

Many thanks,
Stellar