• Neoxia 7
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi,

In a sandbox, I would like to send an email to some users when a particular action is done (i.e. in a trigger on a custom object).

First of all, I configured the access level to "All Emails" in Email Administration > Deliverability.
Then, I use the classic Messaging class/namespace in my trigger :
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
//Test
toAddresses = new List<String> {'some.email@test.com'};

mail.setToAddresses(toAddresses);
mail.setReplyTo('no-reply@test.com');
mail.setSubject('subject');
mail.setPlainTextBody('Test message... Again.');
mail.setHtmlBody('Test message... <br/> <i>Again</i>.');

Messaging.SendEmailResult[] results = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }, false);
System.debug('Email invocations : ' + Limits.getEmailInvocations());
	
//errors
List<Messaging.SendEmailError> errors = new List<Messaging.SendEmailError>();
for(Messaging.SendEmailResult currentResult : results) {
	System.debug('Success : ' + currentResult.isSuccess());
}
In my debug logs, I clearly read "Success : true" for each mail this function has to send. But in my mailbox, nothing to read.
I also logged the number of sent emails with "Limits.getEmailInvocations()". It always increases...

In some forums, I read that it could be a problem with the sandbox (https://developer.salesforce.com/forums/ForumsMain?id=906F000000091ECIAY). Any idea or experience here ?

Thanks !
Hi,

In a sandbox, I would like to send an email to some users when a particular action is done (i.e. in a trigger on a custom object).

First of all, I configured the access level to "All Emails" in Email Administration > Deliverability.
Then, I use the classic Messaging class/namespace in my trigger :
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
//Test
toAddresses = new List<String> {'some.email@test.com'};

mail.setToAddresses(toAddresses);
mail.setReplyTo('no-reply@test.com');
mail.setSubject('subject');
mail.setPlainTextBody('Test message... Again.');
mail.setHtmlBody('Test message... <br/> <i>Again</i>.');

Messaging.SendEmailResult[] results = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }, false);
System.debug('Email invocations : ' + Limits.getEmailInvocations());
	
//errors
List<Messaging.SendEmailError> errors = new List<Messaging.SendEmailError>();
for(Messaging.SendEmailResult currentResult : results) {
	System.debug('Success : ' + currentResult.isSuccess());
}
In my debug logs, I clearly read "Success : true" for each mail this function has to send. But in my mailbox, nothing to read.
I also logged the number of sent emails with "Limits.getEmailInvocations()". It always increases...

In some forums, I read that it could be a problem with the sandbox (https://developer.salesforce.com/forums/ForumsMain?id=906F000000091ECIAY). Any idea or experience here ?

Thanks !