+ Start a Discussion
aklkkaklkk 

how to send a email when is inserting a Records in costume Object then send a email multiple person by Trigger

Hi Every one 


Please support me 

how to send a email when is inserting a Records in costume Object then send a email to multiple person by Trigger ?

peson means (to send multiple salesfroce users)


Thanks 
aklkk
 
Jasveer Singh 15Jasveer Singh 15
trigger TriggerName on YourObjectName__c (after insert) {
  set<String> userId = new set<String>();
  List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
  List<User> userList = [Select firstname,lastname,email from User Limit 5];
  for (User u : userList) {
      userId.add(u.Email);
  }
    Messaging.SingleEmailMessage mail =  new Messaging.SingleEmailMessage();
    List<String> sendTo = new List<String>();
    sendTo.addAll(userId);
    mail.setToAddresses(sendTo);
    mail.setReplyTo('info.jasveer@gmail.com');
    mail.setSenderDisplayName('Jasveer Singh Bagri');
   
    mail.setSubject('New Record was inserted');
    String body = 'Dear ';
    mail.setHtmlBody(body);
    mails.add(mail);
        Messaging.sendEmail(mails);
    }
  }