You need to sign in to do that
Don't have an account?
venkateshyadav1243
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
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 !
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) {
}
}
}
}
what is the actual problem ? are you getting any error or you want to do something else ?
am not geting any error am geting only email
opportunity selected closed won.
but i want all filed of opportunity details to my email
Then add all fields in your html body just like you adding user1.name !
hi thanks vijay
thanks
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
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) {
}
}
}
}
thankssssssssssssssss
so much vijay now its working thanks