+ Start a Discussion
naveen kunurunaveen kunuru 

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;
        }
        

}
 
Rahul Sangwan7341Rahul Sangwan7341
Hi Naveen,

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.
naveen kunurunaveen kunuru
hey ,i got this error
Visualforce ErrorHelp for this Page
System.NullPointerException: Attempt to de-reference a null object 
Class.emailclass.<init>: line 7, column 1
Himanshu ParasharHimanshu Parashar
Hi Naveen,

You can use following code. you forgot to initialize contactids list
 
public with sharing class emailclass {
public list<id> contactids;
public emailclass(){
       contactids = new list<id>();

       for(Contact con : [select id from contact limit 10])
       {
           contactids.add(con.id);
       } 
 }
  public PageReference sendemail() {
    Messaging.MassEmailMessage mail=new Messaging.MassEmailMessage();
    mail.settargetobjectids(contactids);
    Message.sendemail(new Messaging.MassEmailMessage[]{mail});
 
        return null;
        }
        

}


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.

 
Tejpal KumawatTejpal Kumawat
Hello Naveen,

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!
Luis MolinaLuis Molina
How the message is sent to the template? I only see the shipping ids of users but not the message body. That is, "Pepe hello how are you". Where it gets?