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
venkateshyadav1243venkateshyadav1243 

trigeer for opportunity

i have a scenario when am selected stage is closed won on opportunity i have to get email and also i have to get the user fill the detail like profit opprtunity name and emaill etc on the opprtunity

vijaymindvijaymind

Not a issue you email when a opportunity create or upate with the opportunity id as linked url in the email so that user can click on that link and login in to the salesforce and update the records accordingly !

 

 

venkatyadav127venkatyadav127

hi

 

thanks for your replay

 

this is my code plz check it where i have to modify

 

 trigger SendEmail on Opportunity (after insert)
 {
 
                if(trigger.new[0].StageName == 'closed Won')
                {
                                user user1=[select id  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) {       
 
            }
 
        }     
      
    }
    }

vijaymindvijaymind

what is the actual problem ? are you getting any error or you want to do something else ?

venkatyadav127venkatyadav127

am not geting any error am geting only email

opportunity selected closed won.

 

 

but i want all filed of opportunity details to my email

vijaymindvijaymind

Then add all fields in your html body just like you adding user1.name !

venkatyadav127venkatyadav127

hi thanks vijay

thanks

venkatyadav127venkatyadav127

can u send me one exalme bcz am tryinbg to add but am geting error

 

i have this fileds plz add and send me

 

opportunity Name

Account Name

Type

vijaymindvijaymind

trigger SendEmail on Opportunity (after insert)
{

if(trigger.new[0].StageName == 'closed Won')
{
user user1=[select id 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 = body + trigger.new[0]

body += '<b>\n Hello: '+user1.name+'</b>';
body += '<b>\n'+trigger.new[0].Name+'</b>';;
body += '<b>\n'+trigger.new[0].Account.Name+'</b>';



mail.setHtmlBody(body);



try {

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

} catch(Exception ex) {

}

}

}
}

venkatyadav127venkatyadav127

thankssssssssssssssss

so much vijay now its working thanks