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
raz rraz r 

Getting error "Invalid type: Messaging.SingleEmailMessage"

public with sharing class EmailManager{

    public void sendMail(String address, String subject, String body) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {address};
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });


Amit Chaudhary 8Amit Chaudhary 8
Please check below post I hope that will help you
public static void sendEmail(String s, List<Idea> myIdea) {

 // Send an email back to the from email address of who created the idea
 String[] toAddresses = new String[] {s};

 // new instance of a single email message
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

   mail.setSenderDisplayName('Salesforce Ideas!');
   mail.setSubject('New Idea['+myIdea[0].Id+'] created - '+ myIdea[0].Title);
   mail.setPlainTextBody('Your Idea: ' + myIdea[0].Title +' has been created \n Check out your new idea \n\n To watch you idea in click on this link \n'+myIdea[0].Id);
 // Send the email
 Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

public class singleEmailExample
public PageReference sendingEmail()
Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
String[] sendingTo = new String[]{‘’};
String[] sendingToBccAdd = new String[]{‘’};
String[] sendingTocAdd = new String[]{‘’};
semail.setSubject(‘Single Email message Example’);
semail.setPlainTextBody(‘Hello!!!!!!!!!!This is a test email to test single email message program’);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
return null;
Please let us know if this will help u

raz rraz r
Hello Amit,

Can you please suggest me , why this error occrs in my code.
raz rraz r
Hi All Any body reply on this .