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
Jayesh Deo 2Jayesh Deo 2 

how to collect lookup relation associated record ID from child record?

Hiring_Manager__c =Parent Object
Recruiter__cm = Child Object (Lookup relation)

I am trying to collect hiring manager ID  from recruiter object as shown in below query.

 Public Static Void AfterUpdate(Map<ID, Hiring_manager__c> MapHrRecords)
    { 
        List <Recruiter__c> LstRecruiters=[select id, name , location__c, Email__c, Phone__c, HiringManagerid__c 
                                           from recruiter__c 
                                                  where HiringManagerid__c IN:MapHrRecords.keySet() ];
        
    }

ERROR encountered:
No such column 'HiringManagerid__c' on entity 'Recruiter__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

 
Best Answer chosen by Jayesh Deo 2
Jayesh Deo 2Jayesh Deo 2
Hi Swetha,

Thank you for the response.
I Updated below mentioned query to fetch details from child object which has associated parent ID via lookup relation. 

Public Static Void AfterUpdate(Map<ID, Hiring_Manager__c> MapHrRecords)
    { 
        List <Recruiter__c> LstRecruiters=[select id, name , location__c, Email__c, Phone__c, Hiring_Manager__r.id 
                                           from recruiter__c 
                                                  where Hiring_Manager__r.id IN:MapHrRecords.keySet() ];
}
 

All Answers

SwethaSwetha (Salesforce Developers) 
HI Jayesh,

Ensure that the API name of the lookup field on the 'Recruiter__c' object that relates it to the 'Hiring_manager__c' parent object is correct. API names are case-sensitive, so they must match exactly as they are defined in your Salesforce org.

Related:
https://salesforce.stackexchange.com/questions/375357/how-to-query-child-records-of-the-lookup-record-in-a-single-query

If this information helps, please mark the answer as best. Thank you
Jayesh Deo 2Jayesh Deo 2
Hi Swetha,

Thank you for the response.
I Updated below mentioned query to fetch details from child object which has associated parent ID via lookup relation. 

Public Static Void AfterUpdate(Map<ID, Hiring_Manager__c> MapHrRecords)
    { 
        List <Recruiter__c> LstRecruiters=[select id, name , location__c, Email__c, Phone__c, Hiring_Manager__r.id 
                                           from recruiter__c 
                                                  where Hiring_Manager__r.id IN:MapHrRecords.keySet() ];
}
 
This was selected as the best answer