Skip to main content
Hi, Please can someone solve this error and can someone suggest to me how to write a test class for the following code. Because I am getting this error - Methods defined as TestMethod do not support getContent call

public class sendEmail {

public String subject { get; set; }

public String body { get; set; }

 

private final Account account;

 

// Create a constructor that populates the Account object

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() {

// Define the email

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

 

// Reference the attachment page and pass in the account ID

PageReference pdf = Page.attachmentPDF;

pdf.getParameters().put('id',(String)account.id);

pdf.setRedirect(true);

 

// Take the PDF content

Blob b = pdf.getContent();

 

// Create the email attachment

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

efa.setFileName('attachment.pdf');

efa.setBody(b);

 

String addresses;

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

addresses = account.Contacts[0].Email;

// Loop through the whole list of contacts and their emails

for (Integer i = 1; i < account.Contacts.size(); i++) {

if (account.Contacts[i].Email != null) {

addresses += ':' + account.Contacts[i].Email;

}

}

}

 

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

 

// Sets the paramaters of the email

email.setSubject( subject );

email.setToAddresses( toAddresses );

email.setPlainTextBody( body );

 

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

 

// Sends the email

Messaging.SendEmailResult [] r =

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

return null;

}

}

 
4 Antworten
0/9000