You need to sign in to do that
Don't have an account?
aam1r
Call Visualforce Page Method from Apex Class
Call Visualforce Page Method from Apex Class
Hi everyone,
Is it possible to call a VF page from another apex class? I currently have a vf page that generates a document and emails it to the contact on an opportunity. This is executed via an action button.
I have created a lightning component that enlists filtered opportunities and I want to click a button to send the above generated documents, per opportunity to their linked contacts.
The VF page has the following variables:
Method does not exist or incorrect signature: void CreateAndSendPdf() from the type System.PageReference
Sorry, I’ve not included all the code as there’s quite a lot of it, but the essentials are included.
Any ideas how I can achieve this?
aam1r
Hi everyone,
Is it possible to call a VF page from another apex class? I currently have a vf page that generates a document and emails it to the contact on an opportunity. This is executed via an action button.
I have created a lightning component that enlists filtered opportunities and I want to click a button to send the above generated documents, per opportunity to their linked contacts.
The VF page has the following variables:
<apex:variable var="CompanyName" value="{!CompanyName}" /> <apex:variable var="OppId" value="{!OppId}" /> <apex:variable var="year" value="{!year}" /> <apex:variable var="emailStr" value="{!emailStr}" />The VF page controller has the following class members:
public String CompanyName {get;set;} public String OppId {get;set;} public Integer year {get;set;} public String emailStr {get;set;}and has the following method in the VF page controller is what I want to call that creates the document and sends the email:
public PageReference CreateAndSendPdf() {I need to be able to set the above parameters and then call the method from the new batch class. What I’ve tried so far is:
if (lstValidOpps.size() > 0){ for (Opportunity o : lstValidOpps){ PageReference pr = new PageReference('/apex/vfPage'); // set query string parameters and values for the page pr.getParameters().put('oppId',o.Id); pr.getParameters().put('year','2028'); pr.getParameters().put('emailStr','aam1r@mail.com'); //pr.CreateAndSendPdf(); // This line fails } } }However I get an error when I save the batch class. Line pr.CreateAndSendPdf() throws:
Method does not exist or incorrect signature: void CreateAndSendPdf() from the type System.PageReference
Sorry, I’ve not included all the code as there’s quite a lot of it, but the essentials are included.
Any ideas how I can achieve this?
aam1r
Here is an extract showing the vf page controller class' constructor method: And i've changed the code in the batch class to be: Now this saves but when running it fails when the 'vfPageController' constructor is called, on the following, which is returning null: The vf page runs fine, but i can't get passed this stage. How can i bypass the member assignments in the constructor when instantiating the class in this way?