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?

3
  • Are you sure it has one?
    – Adrian Larson
    Jul 12, 2015 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, 2015 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. Jul 12, 2015 at 22:18

0

You must log in to answer this question.

Browse other questions tagged .