if(objQuote .Status=='Accepted' && objQuote.ContactId !=Null) { // Set parameters to Messagin.singleEmailMessage
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setTemplateId(' '); // Give templateId here mail.setTargetObjectId(objQuote.ContactId); // Give necessary WhatId, Whoid. To Address , From Address as per your requirement // mail.setWhatId(contactList[0].OpportunityId); Messaging.sendEmail(new Messaging.Singleemailmessage[] {mail});
Hi Narendra , Just replace the quote object in my example with contact . If you want to check the changing value with the new one you need to use trigger.old .
http://stackoverflow.com/questions/17860289/apex-beginner-email-from-a-trigger
You can do it in a following way :
for(Quote objQuote :trigger.new){
if(objQuote .Status=='Accepted' && objQuote.ContactId !=Null)
{
// Set parameters to Messagin.singleEmailMessage
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId(' '); // Give templateId here
mail.setTargetObjectId(objQuote.ContactId); // Give necessary WhatId, Whoid. To Address , From Address as per your requirement
// mail.setWhatId(contactList[0].OpportunityId);
Messaging.sendEmail(new Messaging.Singleemailmessage[] {mail});
}
}
Thanks ,
Ajay
i want . when we update contact filed through trigger .. then send email after updation so plz give me a example contact
Just replace the quote object in my example with contact .
If you want to check the changing value with the new one you need to use trigger.old .
Thanks ,
Ajay
thanks
i have done for this code..
trigger Sendemail on Contact (after insert,after update) {
//String[] emails = new String [] {'j'};
for (Contact c: trigger.new) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String emailAddress= [select email from contact where id=:c.id].email;
mail.setTargetObjectId(c.id);
String[] toAddresses = new String[] {emailAddress};
mail.setToAddresses(toAddresses);
//mail.setToAddresses(toAdd );
mail.setSubject('contact');
URL currentURL = URL.getCurrentRequestUrl();
mail.setHtmlBody('view ur contact'+currentURL);
// emails.add(mail);
Messaging.sendEmail(new Messaging.SingleEmailmessage[] { mail } );
}
}