• Scott-3823
  • 0 Points
  • Member since 2012

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 2

With the Winter '13 release of Salesforce, they have added native trigger support for Opportunity Teams (previously Selling Teams).  We would like to have our users notified when they are added to a Opportunity Team.  I have written the code below.


trigger EmailTeamMember2 on OpportunityTeamMember (after insert) {

    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

    for (OpportunityTeamMember o : trigger.new) { 
    String[] toAddresses = new String[] {o.User.email};

    mail.setReplyTo ('support@acme.com');
    mail.setSenderDisplayname('Salesforce Support');
    mail.setSubject('Added to an Opportunity Team : ');
    mail.setPlainTextBody('You have been added to the Opportunity Team of: ' + o.Opportunity);
    mail.setHtmlBody('You have been added to the Opportunity Team of:<b> '+ o.Opportunity+');
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });


 It saves without any errors, but when I try to add a team member this error appears:


Apex trigger EmailTeamMember2 caused an unexpected exception, contact your administrator: EmailTeamMember2: execution of AfterInsert caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Invalid to address : null: []: Trigger.EmailTeamMember2: line 16, column 1  


Thanks for your help in advance!!! :)

Is there any way to get the profile name of logged in user without querying the user object.


I know the following solution:


String usrProfileName = [select u.Profile.Name from User u where u.id = :Userinfo.getUserId()].Profile.Name;


Instead of this I want to save 1 query so if there is any method to get the profile name in apex without firing the query please let me know.