Whenever a case is opened and closed for an account of a particular region the respective inside rep for that account should get email alert notification.

1.2K    Asked by AudreyBerry in Salesforce , Asked on Oct 2, 2020
Answered by Audrey Berry

Trigger caseTrigger on Case(after insert){

   // Generate handler class

   caseTriggerHandler.afterInsert(trigger.new);

}

public class void CaseTriggerHandler{

    public static void afterInsert(List newList){

     list accId = new list();

     for(case c: newList){

      if(c.account__c != null)

       accId.add(c.account__c );

     }

     //query email address from account object.

     Map insideSalesEmailMap = [select id, inside_sales__c from account where id IN :accId];

     // preparing for Email send out.

     List sme = new List();

     for(case c: newList){

      Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

      email.setTemplateId('put template id');

      email.setToAddresses(insideSalesEmailMap.get(c.account__c));

      email.targetObjectId(c.id);

      email.setSaveAsActivity(false);

      sme.add(email);

     }

     //send Email

     if(sme != null && sme.size() > 0)

      Messaging.sendEmail(sme);

  }

}



Your Answer

Interviews

Parent Categories