I have a map of opportunity Id and list of opportunityteammember. I have putted in list of opportunityteammember user.Email , User.Name etc. I need to send mail to that user's email address. For that i have done below, but its not working. Please help.

Map<Id, List<OpportunityTeamMember>> mapOppId_usrEmail = new Map<Id, List<OpportunityTeamMember>>(); 

for(OpportunityTeamMember otmtoAdd : [SELECT OpportunityId, Opportunity.stageName, 
                                             User.Email, User.Name 
                                         FROM OpportunityTeamMember 
                                         WHERE (Teammemberrole ='Sales Rep' OR 
                                                Teammemberrole ='Sales Engineer') AND 
                                               OpportunityId IN : setOppId]){   
      mapOppId_usrEmail.put(otmtoAdd.OpportunityId, new List<OpportunityTeamMember>{otmtoAdd});
   system.debug('test system : '+otmtoAdd.User.Email);
system.debug('#### mapOppId_usrEmail - '+ mapOppId_usrEmail);

In first system.debug(test system :) i am getting value as email ex:[email protected]. But in 2nd system.debug(#### mapOppId_usrEmail - '+ mapOppId_usrEmail) i am not getting user Email and user name in map. So that i am unable to send mail to that address.

  • System.debug output normally only shows the fields of the object not parent object fields. I suggest you add debug output that explicitly outputs the parent object fields via the User reference: the code looks OK to me so I'd expect the email etc to be there.
    – Keith C
    Jul 11, 2015 at 21:07

1 Answer 1


To Kieth's comment above, I was able to verify that the email of the user actually exists by adding the below debug to your code:

system.debug('### mapOppId Email - ' + mapOppId_usrEmail.values()[0][0].user.email);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .