You need to sign in to do that
Don't have an account?

Sending 400 emails using custom button
I am trying to create a custom button on List View (Lightning) for sending emails to over 400 people ... All emails will contain personalized info so doing a cc and bulkifying email recepients isn't an option.
I have a custom button on a list view ( which is made up of a VF page) and has ability to select upto 400 records.
The controller for that page is working on a for-loop , but I still ended up with sendMail limit error (cannot execute more than 10 sendMail)
Not exactly sure how an I circumvent this limit.
Creating an out-of-the-box (WF based) email alert on a value update isn't also an option since the records will be locked.
If anyone has any idea, let me know.
Thanks in advance.
I have a custom button on a list view ( which is made up of a VF page) and has ability to select upto 400 records.
The controller for that page is working on a for-loop , but I still ended up with sendMail limit error (cannot execute more than 10 sendMail)
public class ExpertEmailController { public sObject[] mAct; ApexPages.StandardSetController selectedRec; String redirectUrl = System.Label.Redirect_Url; public ExpertEmailController(ApexPages.StandardSetController controller){ controller.setPageSize(400); selectedRec = controller; } public PageReference sendMail(){ // Send Email for ( Monthly_Activity__c ma : (Monthly_Activity__c[])selectedRec.getSelected() ){ mAct = [SELECT Email FROM sObject WHERE Id =: ma.Id LIMIT 1]; // Create body string body = 'Dear '+ mAct[0].User +', '+'\n\n'; body += 'BODY'+'\n\n'; Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setToAddresses(new String[] {mAct[0].Email}); mail.setSenderDisplayName('Salesforce Administrator'); mail.setSubject('Record'); mail.setPlainTextBody(body); Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{mail}); } PageReference page = new PageReference(redirectUrl); page.setRedirect(true); return page; } }
Not exactly sure how an I circumvent this limit.
Creating an out-of-the-box (WF based) email alert on a value update isn't also an option since the records will be locked.
If anyone has any idea, let me know.
Thanks in advance.
List<Messaging.SingleEmailMessage> myEmails = new List<Messaging.SingleEmailMessage>();
Replace below code with Highlighted code
Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{mail});
myEmails.add(mail);
Add below code after for loop
Messaging.sendEmail(myEmails);