So I have a lightning component that will open a visualforce page when you click the pdf button. The visualforce page opens in pdf format but I can't call the Apex variable to get the Account Name, Type etc. For simplicity I've only posted the relevant code. How can I call the apex variable to display account fields on the vfp page?

enter image description here Aura:

<aura:attribute name="searchResult" type="List"/>
<aura:attribute name="searchString" type="String"/>     
<aura:attribute name="Message" type="boolean" default="false"/>     
<aura:attribute name="id" type="object"/>

<aura:iteration items="{!v.searchResult}" var="account">
        <td><div class="slds-truncate" title="{!account.Name}">{!account.Name}</div></td>
        <td><div class="slds-truncate" title="{!account.Type}">{!account.Type}</div></td>

      <!-- Use a Lightning Base Component To display an icon next to the label -->



 downloadPDF : function (component, event, helper)
        //get acc id from pdf button
        var myId = event.getSource().get('v.value'); 
        //call apex controller
        var action = component.get("c.DisplayAccounts");
        //set variable equal to acc id
        action.setParams({'pdfSearch': myId});
            var state = response.getState();
            if(state === "SUCCESS"){
                window.open('/apex/AccountPDFViewer?id=' + myId);

                console.log('unable to generate the pdf');



public class AccountPDFController
    public String PDFData {get;set;}
    public static Account acc{get;set;}

    public AccountPDFController()
        acc = new Account();
    public static Account DisplayAccounts(String pdfSearch)
        String secondSearch = pdfSearch;
        List < Account > pdfList = [SELECT Id, name, Type FROM Account Where Id=:secondSearch];
        system.debug('Apex Step 4');
        acc = pdfList[0];
        system.debug('Apex step 5');
        return acc;



<apex:page controller="AccountPDFController" renderas="PDF">
    <apex:outputText value="{!acc.Name}"/>

1 Answer 1


You will need standardController in apex page:

<apex:page standardController="Account" extensions="AccountPDFController " >
    name - {!Account.Name}

You dont need any declaration of extra variable like acc. Standard controller Account itself acts as accessor. You extension controller should constructor with standard controller parameter:

public class AccountPDFController {

    public AccountPDFController(ApexPages.StandardController controller){}

  • Thanks! Worked perfect, why does it not work the other way?
    – Tyler
    Aug 12, 2019 at 15:26
  • It will work if you query the account in constructor by getting the Id parameter from url. Much more complex than using standard controller. Aug 12, 2019 at 15:27
  • Oh okay, thanks for the help! I still have much to learn
    – Tyler
    Aug 12, 2019 at 15:32
  • Is there anyway I could pm you? I have another question about querying from constructor. I actually just ran into another project with that as a use case
    – Tyler
    Aug 12, 2019 at 19:33
  • not sure how pm works in SFSE. I am actually new to this platform. However I answered your question :) Aug 13, 2019 at 3:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .