0

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.

Which one i should use setToaddress or SetTargetObjectId and how?

0

If you want to send outbound emails you don't need targetobjectid. Just use setToaddress. Don't forget to split your emails from custom field (in case that you store emails separeted by comma).

List<String> emailsFromRecordList = myCustomObjectRecord.EmailIds__c.split(',');
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.toAddresses = emailsFromRecordList;
message.subject = 'Opt Out Test Message';
message.plainTextBody = 'This is the message body.';
Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};

PS: Don't forget about these items:

  1. The maximum number of email addresses allowed is 100;
  2. Emails limits.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.