I have custom object and custom object field which is a lookup to Account. I am able to retrieve account record value from the lookup field but I am getting only the id of the record . I need to get the name of the record.

for eg: The record name is 'Ac_record' and the ID is '123456609xya', I am only getting the id not the name of the Account record.

How can I achieve it?

my code:

 obj = select id, name, Location__c from customObj__c where id in: setId;
 srting location = obj.Location__c;

location__c is lookup to Account, please help me solve this issue.

1 Answer 1


You can use

obj = select id, name, Location__r.name from customObj__c where id in: setId;

You must log in to answer this question.

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