+ Start a Discussion
tgganeshtgganesh 

Send mass email

Hi all,

 

Can anyone tell me how to collect the opportunity id from the list view displaying opportunity record.

 

I have a list view in new opportunity page..

 

 

i should select the opportunity and when i click the send mass email button. it has to collect id of the selected opportunity and mail to the owner of the record.

 

Can anyone give me a solution for this?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
tgganeshtgganesh
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
var userList = {!GETRECORDIDS($ObjectType.Opportunity)};

/*Following code will arrange in proper format */
var SelectedIds='';
for(var i=0;i < userList.length; i++)
{
SelectedIds+="'"+userList[i]+"',";
}
SelectedIds=SelectedIds.substring(0,SelectedIds.length - 1);
alert('select list'+SelectedIds);
/*arrange in proper format Ends */


var updatedList = [];

if (userList[0] == null)
{
alert('Please select at least one record.');
}
else
{

/*Formated Query*/
var strQuery="Select Id,Send_Mass_Email_for_Promotion__c from Opportunity where ID in ("+SelectedIds+")";

var result = sforce.connection.query(strQuery);

var records = result.getArray("records");
alert('records'+records);
/*Formated Query Ends */
for (var n=0; n<records.length; n++)
{
alert('getting inside');
var i = new sforce.SObject("Opportunity");
i.id = records[n].Id;
i.Send_Mass_Email_for_Promotion__c = "true"; // This is a custom checkbox field created in opportunity. 
//we need to create a workflow to send email to the owner of the opportunity.
//The workflow should fire once the field is checked. updatedList.push(i); alert('updatedList'+updatedList); } var upresult = sforce.connection.update(updatedList); if (upresult[0].getBoolean("success")) { window.location.reload(); } else { alert('Error occurred in sending mail :' + upresult[0]); } }

Finally I got solution :)

All Answers

Srikant JoshiSrikant Joshi

Try this code in the custom button using javascript & modify code according to your needs to send email.

 

{!requireScript("/soap/ajax/24.0/connection.js")}
sforce.connection.login("Username", "password+securityToken");

//Get the oppurtunity Id

var oppurId = {!Opportunity.Id};

// single mail request
var singleRequest = new sforce.SingleEmailMessage();
singleRequest.replyTo = "Sender@gmail.com";
singleRequest.subject = "Whatever you want the subject as";
singleRequest.plainTextBody = "Plain Text";
singleRequest.toAddresses = ["reciept@gmail.com"];

var sendMailRes = sforce.connection.sendEmail([singleRequest]);

alert('Sucesssfully sent email');

 

,

 

tgganeshtgganesh
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
var userList = {!GETRECORDIDS($ObjectType.Opportunity)};

/*Following code will arrange in proper format */
var SelectedIds='';
for(var i=0;i < userList.length; i++)
{
SelectedIds+="'"+userList[i]+"',";
}
SelectedIds=SelectedIds.substring(0,SelectedIds.length - 1);
alert('select list'+SelectedIds);
/*arrange in proper format Ends */


var updatedList = [];

if (userList[0] == null)
{
alert('Please select at least one record.');
}
else
{

/*Formated Query*/
var strQuery="Select Id,Send_Mass_Email_for_Promotion__c from Opportunity where ID in ("+SelectedIds+")";

var result = sforce.connection.query(strQuery);

var records = result.getArray("records");
alert('records'+records);
/*Formated Query Ends */
for (var n=0; n<records.length; n++)
{
alert('getting inside');
var i = new sforce.SObject("Opportunity");
i.id = records[n].Id;
i.Send_Mass_Email_for_Promotion__c = "true"; // This is a custom checkbox field created in opportunity. 
//we need to create a workflow to send email to the owner of the opportunity.
//The workflow should fire once the field is checked. updatedList.push(i); alert('updatedList'+updatedList); } var upresult = sforce.connection.update(updatedList); if (upresult[0].getBoolean("success")) { window.location.reload(); } else { alert('Error occurred in sending mail :' + upresult[0]); } }

Finally I got solution :)

This was selected as the best answer