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

custom class method for email send not functioning

I have build a method to handle emailing in a class called TripRptManager.  I requires no parameters.  It is not functioning but returns no errors.  Any ideas.  Thanks 



An Excerp:


The call in the controller is TripRptManager sendEmail;


The class:


public with sharing class TripRptManager {

//Public attributes

//Utility methods
public class SendEmail {
public String subject {get; set;}
public String body {get; set;}
private final Account account;

public SendEmail() {

account = [SELECT Name,
( SELECT Contact.Name, Contact.Email
FROM Account.Contacts)
FROM Account
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];


public Account getAccount() {
return account;

public PageReference send() {

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

PageReference pdf = Page.TripReportPDF;
pdf.getParameters().put('id', (String);

Blob b = pdf.getContent();

Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();

String addresses;
if (account.Contacts[0].Email != null) {
addresses = account.Contacts[0].Email;

for (Integer i = 1; i < account.Contacts.size(); i++) {
if (account.Contacts[0].Email != null) {
addresses += account.Contacts[i].Email;

String[] toAddresses = addresses.split(':',0);

email.setSubject( subject );
email.setToAddresses( toAddresses );
email.setPlainTextBody( body );

email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});

Messaging.SendEmailResult [] r =
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

return null;


Best Answer chosen by Admin (Salesforce Developers) 

In your code, the constructor for SendEmail class will not get triggered unless you create an object of that class. For example, 


SendEmail  s = new SendEmail();


You can acheieve this without using the wrapper class also. If you want to use tha wrapper class, you must create the object of that class in you main class.


Let me knwo if you need any additional information.