You need to sign in to do that
Don't have an account?
Henrique Rodrigues
How to send a email in a trigger
Hi experts, i'm trying to develop a trigger that send an email when a record is created with a condition, but when I insert the record in the object i'm not receive the email.
This is my code:
my test class is working, but the trigger are not working, anybody can help me in this case?
This is my code:
trigger Fila on Fila__c (before insert) { List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); for(Fila__c fila : Trigger.New) { if(fila.Posicao__c == 2){ Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); // list of people who should get the email List<String> sendTo = new List<String>(); sendTo.add('henriquelive19@gmail.com'); mail.setToAddresses(sendTo); // Set email is sent from mail.setReplyTo('henrique@mobiaplicativos.com.br'); mail.setSenderDisplayName('henrique'); // Set email contents mail.setSubject('URGENT BUSINESS PROPOSAL'); String body = 'Dear '; body += 'Email Body.'; mail.setHtmlBody(body); // Add your email to the master list mails.add(mail); try { Messaging.sendEmail(mails); } catch (Exception e) { System.debug('erro' + e); } } } }
my test class is working, but the trigger are not working, anybody can help me in this case?
All Answers