+ Start a Discussion
Jonathan Wolff 7Jonathan Wolff 7 

Account fields do not display after adding Visualforce in List Button

Hello, I build a List button that Includes a Visualforce Page. When I chose Accounts in List view and click account I only see the blank Page without the account fields. Please tell me how to change it.

<apex:page standardController="Account" renderAs="pdf" recordSetVar="accounts" >
 

<h1>Welcome to APP!</h1>
 
<p>Thank you, <b><apex:outputText value=" {!Account.Name}"/></b>, for 
   working with APP.</p>
 
<p>Your account details are:</p>
 
<table>
<tr><th>Account Name</th>
    <td><apex:outputText value="{!Account.Name}"/></td>
    </tr>
<tr><th>Account Rep</th>
    <td><apex:outputText value="{!Account.Owner.Name}"/></td>
    </tr>
<tr><th>Customer Since</th>
    <td><apex:outputText value="{0,date,long}">
        <apex:param value="{!Account.CreatedDate}"/>
        </apex:outputText></td>
    </tr>
</table>
    
</apex:page>

User-added image


Result:

User-added image
Best Answer chosen by Jonathan Wolff 7
Maharajan CMaharajan C
Hi Jonathan,

Please try the below code:
 
<apex:page standardController="Account" renderAs="pdf" recordSetVar="accounts" extensions="AccountListPDFController">
    
    
    <h1>Welcome to APP!</h1>
    
    <apex:repeat value="{!accounts}" var="Account">
        
        <p>Thank you, <b><apex:outputText value=" {!Account.Name}"/></b>, for 
            working with APP.</p>
        
        <p>Your account details are:</p>
        
        <table>
            <tr><th>Account Name</th>
                <td><apex:outputText value="{!Account.Name}"/></td>
            </tr>
            <tr><th>Account Rep</th>
                <td><apex:outputText value="{!Account.Owner.Name}"/></td>
            </tr>
            <tr><th>Customer Since</th>
                <td><apex:outputText value="{0,date,long}">
                    <apex:param value="{!Account.CreatedDate}"/>
                    </apex:outputText></td>
            </tr>
        </table>
    </apex:repeat>
</apex:page>

Apex Class:
 
public class AccountListPDFController {
    public List<Account> accounts{get;private set;}
    public AccountListPDFController(ApexPages.StandardSetController stdSetController){
        accounts = (List<Account>) stdSetController.getSelected();
    }
}

Thanks,
Maharajan.C
​​​​​​​​​​​​​​

All Answers

Maharajan CMaharajan C
Hi Jonathan,

Please try the below code:
 
<apex:page standardController="Account" renderAs="pdf" recordSetVar="accounts" extensions="AccountListPDFController">
    
    
    <h1>Welcome to APP!</h1>
    
    <apex:repeat value="{!accounts}" var="Account">
        
        <p>Thank you, <b><apex:outputText value=" {!Account.Name}"/></b>, for 
            working with APP.</p>
        
        <p>Your account details are:</p>
        
        <table>
            <tr><th>Account Name</th>
                <td><apex:outputText value="{!Account.Name}"/></td>
            </tr>
            <tr><th>Account Rep</th>
                <td><apex:outputText value="{!Account.Owner.Name}"/></td>
            </tr>
            <tr><th>Customer Since</th>
                <td><apex:outputText value="{0,date,long}">
                    <apex:param value="{!Account.CreatedDate}"/>
                    </apex:outputText></td>
            </tr>
        </table>
    </apex:repeat>
</apex:page>

Apex Class:
 
public class AccountListPDFController {
    public List<Account> accounts{get;private set;}
    public AccountListPDFController(ApexPages.StandardSetController stdSetController){
        accounts = (List<Account>) stdSetController.getSelected();
    }
}

Thanks,
Maharajan.C
​​​​​​​​​​​​​​
This was selected as the best answer
Jonathan Wolff 7Jonathan Wolff 7
Hi Maharajan,

I got the following error when Adding the Pdf class:
User-added image
How can I solve this?
Maharajan CMaharajan C
Check is there any other apex class is presented with the same name...

Give other name to you apex class apart from PDFController.
Jonathan Wolff 7Jonathan Wolff 7
Hi Maharajan, it worked. Thank you. Could you just help me with a last topic I got with this. I want, That for every Account A chose the pdf is fully created but on the next page so when I print them they are all seperated for every account. Could you tell me how I can make it the best way ( In addition I would Like to have the Header "Welcome to APP" for every new account, but I think I can achive it myself)

Thank you very much to this point :D
Maharajan CMaharajan C
Hi,

Try the below change:
 
<apex:page standardController="Account" renderAs="pdf" recordSetVar="accounts" extensions="AccountListPDFController">
    
    <apex:repeat value="{!accounts}" var="Account">
        
        <div style="page-break-after:always;">
        <h1>Welcome to APP!</h1>
        
        <p>Thank you, <b><apex:outputText value=" {!Account.Name}"/></b>, for 
            working with APP.</p>
        
        <p>Your account details are:</p>
        
        <table>
            <tr><th>Account Name</th>
                <td><apex:outputText value="{!Account.Name}"/></td>
            </tr>
            <tr><th>Account Rep</th>
                <td><apex:outputText value="{!Account.Owner.Name}"/></td>
            </tr>
            <tr><th>Customer Since</th>
                <td><apex:outputText value="{0,date,long}">
                    <apex:param value="{!Account.CreatedDate}"/>
                    </apex:outputText></td>
            </tr>
        </table>
        
        </div>
        
    </apex:repeat>
</apex:page>

https://salesforce.stackexchange.com/questions/55591/rendering-a-visualforce-page-as-pdf-and-force-page-breaks
https://salesforce.stackexchange.com/questions/46919/how-to-render-multiple-pdfs-from-a-single-visualforce-page/46922#46922​​​​​​​


Thanks,
Maharajan.C
jason jeff 8jason jeff 8
You just need to use the agrregate function as the error describes
 
Select Id,SUM(ReleaseAmount__c) from myObj__c Where nObj__c = 'a0DA00000012fbMMAQ' group by Id
 
That is it. Hope this is what you are looking for 
applinked (http://applinkedapk.info/)