I have created class for sending a email and calling this "class" and "method" in new custom button..This logic works for "Detailed page Button"and for single record but how to make it work for List views for mass Email ?
This is the Class
global class outbound_Emails{ webservice static void SendEmailNotification (){ Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setToAddresses(new string[] {'abc@gmail.com});// mail.setSenderDisplayName('From Name'); mail.setSubject('Sending a Email From SFDC'); mail.setHtmlBody('This is the Body for testing the send email function via custom button, which i should include in list view'); Messaging.sendEmail(new messaging.SingleEmailMessage[] {mail}); } }
This is the button
{!requireScript("/soap/ajax/20.0/connection.js")} {!requireScript("/soap/ajax/20.0/apex.js")} var retStr; retStr = sforce.apex.execute("outbound_Emails", "SendEmailNotification",{}); alert(retStr);
Best Answer
Assuming you have this button on a related list/list view, you can use the {!GETRECORDIDS} javascript function to get the list/array of id of the selected records. You can then send this array to your apex class and then query the email field to get the email. YOu can do something like this: