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
bhanu_prakashbhanu_prakash 

send mail to all leads from button in list view

Hi Team,

I have a button in lead list view as Send mail to all Leads on click on button need to send mail to all users with my custom email template, How can i acheive these functionlaity .

Thanks for advance
Rahul.MishraRahul.Mishra
Hi Bhanu,

To achive this do the following things:

1. Create a check box field 'Send mail to all Leads' with default value as false and hidden from page layout.
2. Now got the existing custom list button and execute the javadcript from there to check that checkbox as true:
{!requireScript("/soap/ajax/23.0/connection.js")}
 
sforce.connection.sessionId = '{!$Api.Session_ID}'; 
var result = sforce.connection.query("Select Id, Send_Email__c  from Lead");
var records = result.getArray("records");
var i;
for (i = 0; i < records.length; i++) { 
var rec = records[i];
var test =  new sforce.SObject("Lead");
test.Id = rec.Id
test.Send_mail_to_all_Leads__c = true; 
var saveResult = sforce.connection.update([test]);
}

3. Create a Workflow on Lead which should fire when Lead is updated and Send_mail_to_all_Leads__c = true, perform following actions from WF :
  1. Send email to all your recipients whome you want to send the email. (make sure to add all your recepinets in email alert)
  2. Update field Send_mail_to_all_Leads__c = false.

In this case, once you hit the custom button, lead will be updated and workflow will trigger to send the email list under email alert which uses your email template.

Mark my answer as solved if it does help you.