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
arosysarosys 

Mass Email Message from apex class

Hi
I wnat to send mass email using template .
In my template i have merge fileds of a custom object .
I am using following code to do it :

Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
         mail.setTargetObjectIds(contactids);
         mail.setTemplateId('00X90000001EePt');
         mail.setWhatId(SelectedId);
         Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });

 

But this gives error setWhatId method does not exist and i saw yes there is no such method.

Any alternative to achieve this ?

 

Thanks

hitesh90hitesh90

Hi arosys,

 

You have to use below method. you missed "s".

 mail.setWhatIds(SelectedId);

 

Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/

arosysarosys

I tried it also its giving following error :

 

Error: Compile Error: Method does not exist or incorrect signature: [Messaging.MassEmailMessage].setWhatIds(String) at line 66 column 6

hitesh90hitesh90

You are passing string instead of ID[] in Parameter because of that it gives you error.
see below link..

MassEmailMessage Methods

 

Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

 

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/

arosysarosys

Yes I know ,  at a time i want to send only one custom object .

Like My scenario is I have a list of surveys in my page .

When a user clicks for a  a particular survey , 

Email should be sent to a mass of people having link of that particular survey.

 

I hope you are getting me.

What should i do ?

hitesh90hitesh90

You have taken.
string SelectedId;  in your code. instead of that you have to use.
ID[] SelectedId;

 

means ID[] datatype instead of string..

 

 

arosysarosys

also there it written :

The values must be one of the following types:

Contract
Case
Opportunity
Product

and mine is a custom object.

hitesh90hitesh90

Yeah.. then you can't use custom object there..

arosysarosys

I did this :

 

ID SelectedId = apexpages.currentpage().getparameters().get('selected');

 

still its giving error :

 

Method does not exist or incorrect signature: [Messaging.MassEmailMessage].setWhatIds(Id)