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
sctdevsctdev 

Reference to an object

 

I have a reference Id from a query of an object to reference another object. How can I use this reference id to either look up the record or directly access the record?

 

 

SCT

Venkat PolisettVenkat Polisett
Please post some code, then we can help you.
sctdevsctdev

for (myContact__c c : [Select Id, Name, Email_Recipient__c Where Name like :contactName Limit 1]) { ); recipId = c.Email_Recipient__c; } insert newC_Report; } catch (System.Exception e) { System.debug('Error: ' + e); }

 Email_Recipient__c is a reference to another object with a field for email address, so I need to access the email address with the recipId from above.

 

In Apex explorer it looks like:

 

Email_Recipeint__c - reference(18)

-       Email_Recipient__r

       -       Email_address__c

 

 

 

Venkat PolisettVenkat Polisett

To get to the email address, use the below in your SOQL:

 

Email_Recipient__r.Email_address__c

sctdevsctdev

I was making it harder than it was.

 

Thanks,