You need to sign in to do that
Don't have an account?
naveen kunuru
<apex:page Controller="emailclass">
<apex:form >
<apex:commandButton value="sendmail" action="{!sendemail}"/>
</apex:form>
</apex:page>
public with sharing class emailclass {
public list<id> contactids;
public emailclass(){
list<contact> con=[select id from contact limit 10];
for(integer i=0;i<10;i++)
{
contactids.add(con[i].id);
}
}
public PageReference sendemail() {
Messaging.MassEmailMessage mail=new Messaging.MassEmailMessage();
mail.settargetobjectids(contactids);
Message.sendemail(new Messaging.MassEmailMessage[]{mail});
return null;
}
}
Error Error: emailclass Compile Error: Variable does not exist: Message at line 13 column what that it mean this code sufficient to send mass email
<apex:page Controller="emailclass">
<apex:form >
<apex:commandButton value="sendmail" action="{!sendemail}"/>
</apex:form>
</apex:page>
public with sharing class emailclass {
public list<id> contactids;
public emailclass(){
list<contact> con=[select id from contact limit 10];
for(integer i=0;i<10;i++)
{
contactids.add(con[i].id);
}
}
public PageReference sendemail() {
Messaging.MassEmailMessage mail=new Messaging.MassEmailMessage();
mail.settargetobjectids(contactids);
Message.sendemail(new Messaging.MassEmailMessage[]{mail});
return null;
}
}
Very Simple thing you are missing............you have to write
Messaging.sendemail(new Messaging.MassEmailMessage[]{mail});
instead of
Message.sendemail(new Messaging.MassEmailMessage[]{mail});
Please Mark this as Best Answer if it helps you to solve your issue.
Visualforce ErrorHelp for this Page
System.NullPointerException: Attempt to de-reference a null object
Class.emailclass.<init>: line 7, column 1
You can use following code. you forgot to initialize contactids list
Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Page :
<apex:page Controller="emailclass">
<apex:form >
<apex:commandButton value="sendmail" action="{!sendemail}"/>
</apex:form>
</apex:page>
Class :
public with sharing class emailclass {
public list<string> contactids;
public emailclass(){
list<contact> con=[select id from contact limit 10];
contactids = new list<string>();
for(integer i = 1; i <= con.size(); i++){
contactids.add(con[i].id);
}
}
public PageReference sendemail() {
if(contactids.size() > 0)
Messaging.MassEmailMessage mail=new Messaging.MassEmailMessage();
mail.settargetobjectids(contactids);
Messaging.sendemail(new Messaging.MassEmailMessage[]{mail});
}
return null;
}
}
If this answers your question then hit Like and mark it as solution!