• Southern gal developer
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies
I have created an Email Templete using object fields in the body of the email.

I have a trigger which occurs after the insert of a single record to a custom object I created. After the insert, I would like to send an email to a list of user. 

I found examples of how to do this but. . .how do you send the id of the record you would like to use when using the template with assigned object fields.

This is my code:

trigger WriteNotifications on CustomTable__c (After insert) {

  //This is not the actual select but gives an idea of how I am getting my data
//Declare variable
ID custom_ID;

for (CustomTable__c C_master : Trigger.new) {
        custom_id = C_master.Id;
    }

//Get the list of user ids
    List<User> lstUsed = [select id, name FROM USER where name =: 'Smith'];
   
  List<String> sendTo = new List<String>();

  for (User uses : lstUsed ){
       sendTo.add(uses.Id);
    }

 EmailTemplate et = [Select id from EmailTemplate where name = 'My Template' limit 1];

    Messaging.MassEmailMessage mail = new Messaging.MassEmail Message();
    mail.setTargetObjectIds(sendTo);
    mail.setSenderDisplayName('Sending Person');
    mail.setTemplateId(et.id);
    Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
}
How can pass the custom_ID value to the  Email Temple to reference the record from my custom table?
I have created an Email Templete using object fields in the body of the email.

I have a trigger which occurs after the insert of a single record to a custom object I created. After the insert, I would like to send an email to a list of user. 

I found examples of how to do this but. . .how do you send the id of the record you would like to use when using the template with assigned object fields.

This is my code:

trigger WriteNotifications on CustomTable__c (After insert) {

  //This is not the actual select but gives an idea of how I am getting my data
//Declare variable
ID custom_ID;

for (CustomTable__c C_master : Trigger.new) {
        custom_id = C_master.Id;
    }

//Get the list of user ids
    List<User> lstUsed = [select id, name FROM USER where name =: 'Smith'];
   
  List<String> sendTo = new List<String>();

  for (User uses : lstUsed ){
       sendTo.add(uses.Id);
    }

 EmailTemplate et = [Select id from EmailTemplate where name = 'My Template' limit 1];

    Messaging.MassEmailMessage mail = new Messaging.MassEmail Message();
    mail.setTargetObjectIds(sendTo);
    mail.setSenderDisplayName('Sending Person');
    mail.setTemplateId(et.id);
    Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
}
How can pass the custom_ID value to the  Email Temple to reference the record from my custom table?