0

A SoQL query returns a salesforce object on a look up field. E.g. a long name:

a80000000012345

How do i query that object and get it's fields instead of the salesforce id? I need the name from that salesforce object id.

Example query that is similar to my problem. Fields are made up. I need a list of books from a category:

select category__c from book__c

I have a category table too though:

select name from book_category_c

2 Answers 2

3

Related lists are stored as ids, but appear as names in the front end.

To get your actual name, try this (SampleObject is the name of the object type that you are trying to get the name for) : :

SampleObject sample = [Select Name from SampleObject where id = 'a80000000012345'];

System.debug('The name of the SampleObject is : ' + sample.Name);

If you had a list of objects and you wanted a list of the names, you could do this instead : :

List<SampleObject> samples = [Select Name from SampleObject where id in : (new Map<Id, OtherSampleObject>(otherSample)).keySet()]);

for(SampleObject sample : samples) {
   System.debug('Sample name ' + sample.Name);
}
0

If you want to get all the Books with categories present in Book Category then can try this select id,name,category__c from book__c where category__c in (select id from book_category__c)

You must log in to answer this question.

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