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
venkatyadav127venkatyadav127 

eorror on trigger after sending the email

hi i write one trigger for sending a email its working fine but after 10 times its send email after that it geting error .

 

 

how to i over come that problem please any one know suggest me thanks for all

Best Answer chosen by Admin (Salesforce Developers) 
Shailesh DeshpandeShailesh Deshpande

If you put all of your SingleEmailMessages into a list and then call sendEmail on that list at the end of the job you can send much, much more than 10 emails.

 

Something similar to this:

 

List<Messaging.SingleEmailMessage> msgList = new List<Messaging.SingleEmailMessage>();
for( Integer i = 0; i < listOfTasks; i++ ){
String[] toAddress = new List(); // setToAddresses will only accept a List (array)
toAddress.add(listOfTasks[i].Owner.Email);
String subjectTag = 'Your Subject';
String msgBody = 'Body';

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses( toAddress ); // only takes a List (array) as noted above
mail.setReplyTo( replyAddress );
mail.setSenderDisplayName('My Company Email');
mail.setSubject(subjectTag);
mail.setPlainTextBody( msgBody );

msgList.add(mail);
}

Messaging.sendEmail(msgList);

 


All Answers

SRKSRK

before this u ask for a sloution & i told u to write a wrokflow for sanding email

venkatyadav127venkatyadav127

is there any possibility to over come that???

Shailesh DeshpandeShailesh Deshpande

If you put all of your SingleEmailMessages into a list and then call sendEmail on that list at the end of the job you can send much, much more than 10 emails.

 

Something similar to this:

 

List<Messaging.SingleEmailMessage> msgList = new List<Messaging.SingleEmailMessage>();
for( Integer i = 0; i < listOfTasks; i++ ){
String[] toAddress = new List(); // setToAddresses will only accept a List (array)
toAddress.add(listOfTasks[i].Owner.Email);
String subjectTag = 'Your Subject';
String msgBody = 'Body';

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses( toAddress ); // only takes a List (array) as noted above
mail.setReplyTo( replyAddress );
mail.setSenderDisplayName('My Company Email');
mail.setSubject(subjectTag);
mail.setPlainTextBody( msgBody );

msgList.add(mail);
}

Messaging.sendEmail(msgList);

 


This was selected as the best answer
SRKSRK

As Shailesh said u can make a list of Toaddress but in that case all user sahre same mail

i don't understnd why don't u create a workflow for this

venkatyadav127venkatyadav127

my lead tel me only create through apex

 

 

any way thanks for u r advice.

thanks srk.

SRKSRK

ok....