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
Deepak Sharma 184Deepak Sharma 184 

Getting an error ' constructors cannot be static'

public class EmailManager {
    
    public static sendEmail(String address, String subject, String body)
    {
        Messaging.SingleEmailMessage mail= new Messaging.SingleEmailMessage();
        string[] toAddresses= new string[] {address};
            mail.setToAddresses(toAddresses);
        mail.setSubject(subject);
        mail.setPlainTextbody(body);
        
        Messaging.SendEmailResult[] results = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
        inspectResults(results);
            
    }
    private static boolean inspectResults(Messaging.SendEmailResult[] results)
    {
        Boolean sendResult = true;
        
        for(Messaging.SendEmailResult res:results)
        {
            if(res.isSuccess())
            {
                System.debug('Email sent successfully');
            }
            else{
                sendResult=false;
                system.debug('The following errors occured: '+res.getErrors());
            }  
        }
        return sendResult;
    }
    }
    

 
Best Answer chosen by Deepak Sharma 184
JyothsnaJyothsna (Salesforce Developers) 
Hi,

Please update the  sendEmail() with return type void as below
 
public static  void sendEmail(String address, String subject, String body)

Hope this helps you!

Please mark the answer as Best Answer if it really helped so that it would help others as well in future.

Best Regards,
Jyothsna