function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ShravanKumarBagamShravanKumarBagam 

Using Triggers how can i send a mail?

Hi,

 

  here is my code.Scenario is when a record is created on account object triggers then it will shoot mail.

trigger acctrig on Account (before insert) {

account a=trigger.new[0];


list<string> toaddress=new list<string>();

toaddress.add('shravankumabragam@yahoo.com');



String subject = 'Account Trigger';
String body = 'Hi, Account trigger has been fired,new account has been created.please check on Account object' ;
String Signature = 'B.Shravankumar';

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

mail.setToAddresses(toaddress);
mail.setSenderDisplayName('Salesforce Outbound Notification');
mail.setsubject(subject);
mail.setplaintextbody(body);
mail.setuseSignature(true);

Messaging.sendEmail(new Messaging.singleEmailmessage[]{mail});

}

bob_buzzardbob_buzzard

You haven't told us what's happening when this code executes - is there an error?

ShravanKumarBagamShravanKumarBagam

 

Hi,

 

   When a record is created trigger is fired,but mail is not send

 

bob_buzzardbob_buzzard

Hmm.  I've used this in the past to send emails without problems.  What happens if you turn on debug logging - do you see an email queued?