You need to sign in to do that
Don't have an account?
Deepak 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;
}
}
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;
}
}
Please update the sendEmail() with return type void as below
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