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
chikkuchikku 

How to get record ID of parent object (Contact__c) and child object (Relationship [custom object Name (Tree__c)])?

A Contact__c is the parent of a custom object in our org (Relationship) with tree__c .the same filed name is contact__c in Tree__c object. I would like to get the parent record's ID with the child record's ID any time there is a new Relationship created. How would I get the record ID of the Account record and the Relationship record in an apex class?
ShirishaShirisha (Salesforce Developers) 
Hi Chikku,

Greetings!

If you have created the Custom field of type lookup to the Contact__c Object then you can query the parent record Id and child record Ids as below:

Select Id,Contact__c from Tree__c.

In the above query the custom field(lookup field) is Contact__c then it will retrieve the Ids of the parent record Ids and Id will be the Child record Ids.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri