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
SFDC developer999SFDC developer999 

how to send emails to multiple opportunities at the same time

Best Answer chosen by SFDC developer999
Raj VakatiRaj Vakati
You no need to write the code just to send an email .. you can able to do it bu using workflow or process builder also

All Answers

Raj VakatiRaj Vakati
You can do it mutlipe ways 
  1. Create a flag and update the flag from the list vieww .. Based the flag collect the record and send email by using trigger or workflow or process builder
  2. Creat a list view button to send emails for selected opptys 
Akshay_DhimanAkshay_Dhiman
Hi,
  This is code to send the email on the custom field (Email_Address__c) on the opportunity.
  This class can also run with the help of trigger.   
  
  
public class SendEmail {
    public static void sendEmailOnOpportunity(){
        list<Messaging.SingleEmailMessage> messages =   new List<Messaging.SingleEmailMessage>();
        list<string> emailid=new list<string>();
        try{
            for(opportunity opp:[select id,name,Email_Address__c from opportunity where Email_Address__c!=null]){
                Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
                emailid.add(opp.Email_Address__c);
                system.debug('----------->'+opp);
                msg.setToAddresses(emailid);
                msg.subject = 'Subject Test Message from sales force';
                String body =   'Dear ' + opp.Name+ '<br/>'+
                    '<h2>Email:</h2>'+opp.Email_Address__c+'<br/>'+
                    '<h2>Thank You </h2>'+'<br/>';
                msg.setHtmlBody(body);
                messages.add(msg);
                list<Messaging.SendEmailResult> results = Messaging.sendEmail(messages);
                if (results[0].success) {
                    System.debug('The email was sent successfully.');
                }
                else {
                    System.debug('The email failed to send: ' + results[0].errors[0].message);
                }
            }
        }
        catch(Exception e){
            system.debug(e.getMessage()+'At Line number::'+e.getLineNumber());
        }
    }
}



Hope it helps you!  Mark this as best answer if you find it helpful.

Thanks,
Akshay
Raj VakatiRaj Vakati
You no need to write the code just to send an email .. you can able to do it bu using workflow or process builder also
This was selected as the best answer
SFDC developer999SFDC developer999
Thank you all for your suggestion, I feel Raj's idea fit my requirement. I still dont know how to
1. add a checkbox column to a list view, so that user can select many opportunities in list view
2. custom button in the list view to send email.

Do I need to develop a custom VisualForce Page to do all of this?

Thanks

 
SFDC developer999SFDC developer999
Thank you all for your suggestion, I feel Raj's idea fit my requirement. I still dont know how to
1. add a checkbox column to a list view, so that user can select many opportunities in list view
2. custom button in the list view to send email.

Do I need to develop a custom VisualForce Page to do all of this?

​Thanks