function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
venkatyadav127venkatyadav127 

opportunity on trigger

hi

 

i write one trigger for geting email

 right now am geting email

and also i want get the detail of the user.

below i write trigger for to send email i want the user detail means opprtunity name ,closed date,statge what ever filed in the opportunity i want get that details to my mail id .

 

please can any one know the how to get that detail to my mail id please help me

advance thanks for all.

 

trigger SendEmail on Opportunity (after Insert,after update)
 {
 
                if(trigger.new[0].StageName == 'closed Won')
                {
                                user user1=[select id ,name,email from user where id=:trigger.new[0].ownerid];
 
        
 
        if (user1.email!=null)
         {
             String userName = UserInfo.getUserName();
            User activeUser = [Select Email From User where Username = : userName limit 1];
            String userEmail = activeUser.Email;
 
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();   
              
        String[] toAddresses = new String[] {'venkatesh4.sfdc@gmail.com'};
        
            mail.setToAddresses(toAddresses);
        
 
           
 
            mail.setSubject('Email from salesforce: Opportunity stage selected as closed won');
 
            String body = 'The user ' + userName + ' Create this Contact '+user1.name;
 
            body += '<b>\n Hello: '+user1.name+'</b>';
 
         
 
            mail.setHtmlBody(body);
          
                             
 
            try {
 
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
 
            } catch(Exception ex) {       
 
            }
 
        }     
      
    }
    }

Best Answer chosen by Admin (Salesforce Developers) 
SRKSRK

u create a stirng
Supposr i query Opp & fatch all the details in tempobj proprty of my apex class

 


String body = 'The user ' + userName + ' Create this Contact '+user1.name;

 

body = 'These are the follwing Opp details'+  tempobj.name +' , Opp Stage' + tempob.stage + ','+ tempobj.<whatever field u query in select query>