3

I have a Map, key is opportunityId and value is OpportunityContactRole. In value of map i have Put OpportunityId, contactId , contact.Name , Id etc. I need to get Contact.Name from values of map. For that i have done something but not working Please help , my Code is below:

 Map<Id, OpportunityContactRole> mapOppId_ConId = new Map<Id , OpportunityContactRole>(); 
for(OpportunityContactRole OppConrole :  [SELECT OpportunityId, Contact.Name, ContactId, Contact.Email FROM OpportunityContactRole WHERE isPrimary=true AND Contact.Preferred_Language__c='EN' AND OpportunityId IN : setOppId]){    
    mapOppId_ConId.put(OppConrole.OpportunityId , OppConrole ); 
}

for(Id oppId : mapOppId_ConId.keyset()){
    singleMail.setTargetObjectId(mapOppId_ConId.get(oppId).ContactId); 
    String message   = '\n Dear :'+ mapOppId_ConId.get(oppId).Contact.Name; // added .get here --martin
}

In string message I am not getting contact name. How can I acheive this?

  • Are you sure it has one? – Adrian Larson Jul 12 '15 at 15:11
  • 1
    It appears to me as though you're doing it correctly. You may want to sort your data and/or use a debug statement before putting the data into your map to make certain isEmpty(Contact.Name) == false. – crmprogdev Jul 12 '15 at 15:47
  • Is it possible that the API user performing the query doesn't have sufficient access to the Contact in question. See OpportunityContactRole.ContactId documentation description. – Daniel Ballinger Jul 12 '15 at 22:18
0

Look at the following discussions on how to get Contact.Id from OpportunityContactRole:

https://stackoverflow.com/questions/17529699/opportunitycontactrole-in-salesforce-triggers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.