You need to sign in to do that
Don't have an account?
Tom Guo 19
SOQL Query - Ids and not Values
I am trying to get the Contact Name and Email of the Primary Opportunity Contact. I am having difficulty as what is being returned is the Id of the contact and no email.
Could someone let me know what key piece I'm missing here?
How would I expose Contact.Name and Contact.Email?
Could someone let me know what key piece I'm missing here?
List<OpportunityContactRole> primaryContactInfo = [SELECT OpportunityId, Contact.Name, Contact.Email FROM OpportunityContactRole WHERE OpportunityId ='0063h00000551YKAAY' AND isPrimary = TRUE]; System.debug(primaryContactInfo[0].get((string)'OpportunityId')); System.debug(primaryContactInfo[0].get((String)'ContactId'));
How would I expose Contact.Name and Contact.Email?
Try the below one:
System.debug( ' Email ==> ' + primaryContactInfo[0].getSObject('Contact').get('Email'));
Thanks,
Maharajan.C
All Answers
Hi Tom,
You are debugging 'ContactId' instead of Contact.Name. Try this as below
System.debug(primaryContactInfo[0].get((String)'Contact.Email'));
Share your thoughts!
Thanks,
Sucharita
Thank you for your response.
To provide a bit more detail, I did try what you suggested earlier but I received the following error: System.SObjectException: Invalid field Contact.Email for OpportunityContactRole.
If I simply output primaryContactInfo, I get the following List: DEBUG|(OpportunityContactRole:{OpportunityId=0063h00000551YKAAY, ContactId=0033h000004QLkNAAW, Id=00K3h000000uCULEA2})
Hence I'm able to get the ContactId of the Contact I'm looking for. I have no idea why for example Contact.Email doesn't come up in any form from my query. Any insights?
Try the below one:
System.debug( ' Email ==> ' + primaryContactInfo[0].getSObject('Contact').get('Email'));
Thanks,
Maharajan.C