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
TN AdminTN Admin 

How to send an email to the list of emails picked from a custom field in apex?

Is there any way to send a mail to the list of mails in the custom field?....

We have one custom field in a custom object. User will enter list of emails in one custom text field called "EmailIds" and the user clicks on the button in the same object then it should send email to all user mensioned in the custom field. 
Alba RivasAlba Rivas
Hi,

You can use Messaging.SingleEmailMessage to send an email to at most 100 different addresses.

Is it a string custom field? How are the email recipients stored? Separated by comma? I will assume that for my response:
 
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {customobject__c.customfield__c.split(',')};
mail.setToAddresses(toAddresses);

Check here the documentation: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_outbound_single.htm

Hope that helps.

Regards