+ Start a Discussion
RamyaKrishnaRamyaKrishna 

Retrieving the field id based on field api name

hi,

 

Using getkeyprefix() method i can able to get the object id.

How can i get the field id ?

(I have a custom object E__c with field city__c. Using getkeyprefix() i got object id. but i need to get the field id)

 

Can u suggest me.

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Ankit AroraAnkit Arora

All Answers

Shashikant SharmaShashikant Sharma

I don't thing there is anything like field Id that we have , you can definitly get FieldMap for any Object, using field describe methods. A field map is map of field api name as key and schema.field as value.

 

like this 

 

// Get the sObject describe result for the Account object

Schema.DescribeSObjectResult r = Account.sObjectType.getDescribe();

// Get the field describe result for the Name field on the Account object

Schema.DescribeFieldResult f = Schema.sObjectType.Account.fields.Name;

// Get the sObject describe result for the Account objectSchema.DescribeSObjectResult r = Account.sObjectType.getDescribe();// Get the field describe result for the Name field on the Account objectSchema.DescribeFieldResult f = Schema.sObjectType.Account.fields.Name;

String fieldAPIName = f.getNae();
Ankit AroraAnkit Arora
This was selected as the best answer