here is my scenario.
From a method 'myClass1' I send Account, contact and a list of custom records to a method 'createEmailwithPDF' of another class - 'myClass2'.
'createEmailwithPDF' takes all the inputs and populates it to a VF page. The page is then rendered as pdf and attached to a mail. This method returns the created email back to 'myClass1'.
But, I'm not able to populate the values to VF page from 'createEmailwithPDF'.
I have simplified the scenario for better understanding of the problem.
-------------------CONTROLLER------------------------
public class myClass2{
public string firstName {get; set;}
public string lastName {get; set;}
public string Address1 {get; set;}
public string Address2 {get; set;}
public string Address3 {get; set;}
public date dateValue {get; set;}
public List<Custom__c> Contracts {get; set;}
public void createEmailwithPDF (String fN, String lN, String A1,
String A2, List<custom__c> con)
{
dateValue = system.today();
firstName =fN;
lastName = lN;
Address1 = A1;
Address2 = A2;
contracts = con;
pagereference pg = new pageReference('/apex/myPage');
pg.setRedirect(false);
blob b = pg.getContentAsPdf();
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
efa1.setFileName(Address1+'.pdf' );
efa1.setBody(b);
email.setSubject('Notification' );
email.setToAddresses( new String[]{'[email protected]'} );
email.setPlainTextBody('Test Body');
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new
Messaging.SingleEmailMessage[] {email});
}
}
The VF Page uses the same 'myClass2' controller. It Just maps the Assigned variables.
When I call the 'CreateEmailWithPDF' method from Anonymous window, I am able to get an email with the pdf attachment. But all the variables are assigned as null. the values that I send from the anonymous window are not getting assigned.
I vaguely understand that I need to populate the values in constructor itseld for the varaiables to get assigned. But in my case, I can't do that because my method is getting varaiables from another class.
Please help me with the situation.
Thanks in advance!
createEmailwithPDF
is declared withvoid
so it won't return anything. You need to specify a data type that you want to return. See documentation