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
FdeBergeyckFdeBergeyck 

Use of parent-child relationships

Hello,
 
Is there a way to access data through a parent child relationship without using a querry?
 
I have an object Vehicle__c where the field Driver__c is a lookup to a Contact. I would like to have the AccountId of that contact. I tried the following, but it returns always null (although the AccountId of that Contact is not null):
 

for(Vehicle__c vehicle : System.trigger.new){

System.debug('vehicle.Driver__r.AccountId = '+vehicle.Driver__r.AccountId);

}

Is there another way, or do I have to use a querry?

Thanks for your help,

François de Bergeyck

mschmidtmschmidt
Hello,

Yes, I've heard of a way of accessing these kind of data without using a query but some API.
Is that right? Where to start for that? It isn't the Metadata API, is it?

Maybe somebody can give as a hint. Would be great.

Cheers,
Matthias
jf317820jf317820
I think you must use:

String accountId = [select AccountId from Contact where Id = :vehicle.Driver__c][0].AccountId;


Message Edited by jf317820 on 02-15-2008 09:13 AM
FdeBergeyckFdeBergeyck
Yes, but in this case you're using a query. Is it not possible to access the data directly?