Sending Emails From an Apex Trigger Using a VisualForce template. - El Toro - Find articles about Visualforce, Apex, Force.com and Salesforce in general

Print Preview

Sending Emails From an Apex Trigger Using a VisualForce template.

trigger SFDCTrigger on Task (After Update) {
    for (Task t : trigger.new) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        // String[] ccAddresses = new String[] {'fran.johnson@itron.com'};
        // mail.setCcAddresses(ccAddresses);
        Case c = [SELECT ContactID FROM Case WHERE ID = :t.WhatID];
        mail.setWhatID(c.ID);
        mail.setTargetObjectID(c.ContactID);
        mail.setTemplateID('00X80000001z3Vl');
        mail.setSaveAsActivity(true);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}

comments powered by Disqus

© El Toro . IT @ 2013
Andrés Pérez