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
AmbigaRamAmbigaRam 

Trigger for sending email with Template

 

Hi,

 

I wrote the trigger for sending email with email template .


I need to send some persons as in CC address.

 

The Following is my trigger, Is there an possiblity to add ccaddress in that code. I also want to set orgWideAddress when it is equal to the value in CaseEmail__c.

 

Please help me.

trigger mailnotification on Case (after insert) {
for(case c:trigger.new){
EmailTemplate etc =[SELECT id from EmailTemplate where Name =:'Case Email to Customer'];
If((c.ContactId != null ) ||(c.SuppliedEmail != null)){
Messaging.SingleEmailMessage m = new Messaging.SingleEmailMessage();
m.setTemplateId(etc.id);
for( OrgWideEmailAddress owa : [select id, Address, DisplayName from OrgWideEmailAddress]){
If(owa.Address==c.CaseEmail__c)
m.setOrgWideEmailAddressId(owa.id);}
String userEmail = c.CaseEmail__c;  
m.setReplyTo(userEmail);
m.setTargetObjectId(c.contactId);
m.setWhatId(c.id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { m });
}
}
}

 

Sandeep001Sandeep001

look for SingleMailMessage API at:

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound_single.htm

 

It has methods - setCcAddresses; setBccAddresses

crop1645crop1645

Also keep an eye out for governor limits on APEX outbound email - https://login.salesforce.com/help/doc/en/salesforce_app_limits_cheatsheet.pdf.  If you can work around this by using workflow + email alerts you won't be bound by the APEX limits