Activity Forums Salesforce® Discussions How to Send Multiple Emails which are entered from Vf Page

  • sushant

    Member
    February 9, 2017 at 8:50 am

    Hi Shravani,

    Use this code

     

    public void SendEmail(List<Id> userids){

    Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();

    List<Id> contactIds = new List<Id> ();

    contactIds .add('003Q0000005DYvTIAW');

    contactIds .add('003Q0000005DYvTIAW');

    mail.setTargetObjectIds(contactIds); mail.setTemplateId('00XQ0000000HvBNMA0');mail.setSaveAsActivity(false);

    Messaging.SendEmailResult[] sendEmailResults = Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });

    for (Messaging.SendEmailResult sendEmailResult : sendEmailResults) {

    if(sendEmailResult.isSuccess()){ System.debug('success');}

    else{ System.debug(

    'error');}

    }

    }

    Thanks

  • Louis

    Member
    May 16, 2017 at 10:01 am

    Hi Shravani,

    I hope this code will be helpful for you...

    public with sharing class  sendEmail{

    public String Email{get;set;}

    public String[] toAddresses;

    public student__c stu{set;get;}

    public  sendEmail(){

    stu=[select name,id,email__c from student__c];

    Email=stu.email__c;

    }

     

    public PageReference send(){

    String[] toaddress = new String[]{<b>Email</b>};

    String[] arrTest = Email.split('\\;');

    System.debug(‘arrTest’+'Email :' + toaddress[0]);

    Messaging.SingleEmailMessage email=new Messaging.SingleEmailMessage();

    email.SetToAddresses(<b>arrTest </b>);

    email.SetSubject(Subject);

    email.setTargetObjectIds(object.id);

    email.SetPlainTextBody(Emailbody);

    email1.SetsenderDisplayName('janbask');

    EmailTemplate tem=[select id from EmailTemplate where name='ganesh'];

    email1.setTemplateId(tem.id);

    email.setSaveAsActivity(false);

    messaging.sendEmailResult[]mesg=Messaging.sendEmail(new Messaging.singleEmailMessage [ ]{email});

    if(mesg [0].success) {

    System.debug('The email was sent successfully.');
    } else {
    System.debug('The email failed to send: '+ mesg [0].errors[0].message);
    }
    }

    }

     

     

     

     

  • santhosh

    Member
    May 26, 2017 at 10:48 am

    The Code Shared helped  was very much useful and helpful

    Saleforce Training in Chennai

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos