Sunday 8 February 2015

Trigger on task object by using messaging class

Require ment:
 
/* whenever task is completed we need send
confirmation mail to related account....

*/

Trigger Send_Email on Task (after insert,after update) {

list<account> acc;

for(Task tsk : Trigger.New)
{

if(tsk.status == 'completed'){

acc = [select name,email__C from account where id =: tsk.whatid];
}
}
for(account a :acc){
if(a.email__c != null){

string mal = a.email__C;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {mal};
mail.setToAddresses(toAddresses);  
mail.setSubject('A task owned by you has been updated');  
String body = 'Dear ' + a.name + ', ';
        body += 'I am informing about your task .';
        body += 'I am varaprasad CEO of salesforce.';
        body += 'your task is completed succesfully.. ';
       
mail.setHtmlBody(body);

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


}
}
}

                             

No comments:

Post a Comment

Complete Salesforce CPQ training Free videos

Salesforcestart:: We are excited to announce that our YouTube channel, Salesforcestart, is your one-stop-shop for all things Salesforce CPQ!...