function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Erica ThomasErica Thomas 

Creating Export to Excel Button on Related List using Visualforce Page

Hi All,

I am new at this, so please bare with me. I am trying to create a custom Export to Excel button that would appear on our Account related list "Agency Planning". I am receiving the syntax error: "Error: Export_to_Excel line 4, column 71: Element type "apex:pageblocktable" must be followed by either attribute specifications, ">" or "/>"

I ended line 4 with ">" but the error is still appearing. Any help would be great!

<apex:page standardController="Account" contentType="application/vnd.ms-excel">
    <apex:relatedList="Agency_Planning__c">
        <apex:pageBlock title="Agency Planning">
            <apex:pageBlockTable value="{!Account.Agency_Planning__c}"var="Agency_Planning__c">
                <apex:column value="{!Agency_Planning__c.Accounting_Month}">
                <apex:column value="{!Agency_Planning__c.Planned_New_Business_Commission}"/>
                <apex:column value="{!Agency_Planning__c.Actual_New_Business_Commission}"/>
                <apex:column value="{!Agency_Planning__c.Over_Under}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>   
    </apex:relatedList>                          
</apex:page>


Thanks!
Erica

Best Answer chosen by Erica Thomas
Vinit_KumarVinit_Kumar
Erica,

This is still not correct for me.This should be syntax as per my assumption try midfying the relationship and field name if they are not correct:-
<apex:page standardController="Account" contentType="application/vnd.ms-excel">
    <apex:pageBlock title="Agency Planning">
        <apex:pageBlockTable value="{!account.Agency_Planning__r}" var="item"> // Assuming the relationship name is Agency_Planning__r
            <apex:column value="{!item.Accounting_Month__c}"/> // Assuming field name is Accounting_Month__c
            <apex:column value="{!item.Planned_New_Business_Commission__c}"/>
            <apex:column value="{!item.Actual_New_Business_Commission__c"/>
            <apex:column value="{!item.Over_Under__c}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>                          
</apex:page>

If this helps,please mark it as best answer to help others :)

All Answers

Ramu_SFDCRamu_SFDC
The problem seems to be with this line <apex:column value="{!Agency_Planning__c.Accounting_Month}"> where the end forward slash is not mentioned. Please change this to <apex:column value="{!Agency_Planning__c.Accounting_Month}"/>.

Hope this resolves your issue!
Erica ThomasErica Thomas
Hi Ramu,

Thanks for the quick reply! I added the foward slash, but am still receiving the error. Is there anything else in my code that could cause it?

<apex:page standardController="Account" contentType="application/vnd.ms-excel">
    <apex:relatedList="Agency_Planning__c">
        <apex:pageBlock title="Agency Planning">
            <apex:pageBlockTable value="{!Account.Agency_Planning__c}"var="Agency_Planning__c">
                <apex:column value="{!Agency_Planning__c.Accounting_Month}"/>
                <apex:column value="{!Agency_Planning__c.Planned_New_Business_Commission}"/>
                <apex:column value="{!Agency_Planning__c.Actual_New_Business_Commission}"/>
                <apex:column value="{!Agency_Planning__c.Over_Under}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>   
    </apex:relatedList>                          
</apex:page>
Vinit_KumarVinit_Kumar
Erica,

Your syntax does not seem to be correct for me ,here is one sample code :-

<apex:page standardController="Account">
    <apex:pageBlock title="My Content">
        <apex:pageBlockTable value="{!account.Contacts}" var="item"> 
            <apex:column value="{!item.name}"/> 
            <apex:column value="{!item.phone}"/>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
</apex:page>
so pageblock table value should be "{!account.<Relationship Name>}"
Apex:Column value should be "{!<var>.<fieldname>}"

Go ahead modify the code as per it and you are good to go :)

If this helps,please mark it as best answer to help others :)

Erica ThomasErica Thomas
Thanks Vinit! That helped a lot. I'm getting a  new error though, "Error: Syntax error. Found 'end of formula'" My code with your corrections is below. Can you help again?

<apex:page standardController="Account" contentType="application/vnd.ms-excel">
    <apex:pageBlock title="Agency Planning">
        <apex:pageBlockTable value="{!account.<Agency_Planning__c>}" var="Agency_Planning__c">
            <apex:column value="{!<Agency_Planning__c>.<Accounting_Month>}"/>
            <apex:column value="{!<Agency_Planning__c>.<Planned_New_Business_Commission>}"/>
            <apex:column value="{!<Agency_Planning__c>.<Actual_New_Business_Commission>}"/>
            <apex:column value="{!<Agency_Planning__c>.<Over_Under>}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>                          
</apex:page>

Thanks!
Vinit_KumarVinit_Kumar
Erica,

This is still not correct for me.This should be syntax as per my assumption try midfying the relationship and field name if they are not correct:-
<apex:page standardController="Account" contentType="application/vnd.ms-excel">
    <apex:pageBlock title="Agency Planning">
        <apex:pageBlockTable value="{!account.Agency_Planning__r}" var="item"> // Assuming the relationship name is Agency_Planning__r
            <apex:column value="{!item.Accounting_Month__c}"/> // Assuming field name is Accounting_Month__c
            <apex:column value="{!item.Planned_New_Business_Commission__c}"/>
            <apex:column value="{!item.Actual_New_Business_Commission__c"/>
            <apex:column value="{!item.Over_Under__c}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>                          
</apex:page>

If this helps,please mark it as best answer to help others :)
This was selected as the best answer
Erica ThomasErica Thomas
Hi Vinit,

Thank you so much for your help! That worked! I really appreciate it. I'm new to apex and was having so much difficulty understanding what I was doing wrong. Thanks again!
Vinit_KumarVinit_Kumar
Happy to help Erica !!
Ryan YoungRyan Young
Erica, this is very interesting to me. Can you post the full code and test wo others can see?
Erica ThomasErica Thomas
Hi Ryan,

The code is below. I used it to create a visualforce page that I then referenced in my custom Export to Excel button.

<apex:page standardController="Account" contentType="application/vnd.ms-excel">
    <apex:pageBlock title="Agency Planning">
        <apex:pageBlockTable value="{!account.Agency_Planning__r}" var="item">
            <apex:column value="{!item.Accounting_Month__c}"/>
            <apex:column value="{!item.Planned_New_Business_Commission__c}"/>
            <apex:column value="{!item.Actual_New_Business_Commission__c}"/>
            <apex:column value="{!item.Over_Under__c}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>                          
</apex:page>
Justin Epistola 1Justin Epistola 1
Hi Erica, I tried following your guide; 

<apex:page standardController ="OnePlace__Function__c" contentType="application/vnd.ms-excel">
    <apex:pageBlock title="Invitees">
        <apex:pageBlockTable value="{!OnePlace__Function.OnePlace__Invitee__r}" var="item"> 
            <apex:column value="{!item.Name}"/> 
            <apex:column value="{!item.Initial_Contact__c}"/>
            <apex:column value="{!item.Investor_Contact__c"/>
            <apex:column value="{!item.NDA_Sent__c}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>                          
</apex:page>

When Saving I am getting an error; 
Error: Unknown property 'OnePlace__Function__cStandardController.OnePlace__Function'

I am new to VF, thank you for helping!
kaushik Krishnan 15kaushik Krishnan 15
Hi Everyone,
I have similar requirement, let me know if its correct.
I am not able to view VF page as content in List Button.

Here is my Code

<apex:page standardController="Account" extensions="AccountPage" contentType="application/vnd.ms-excel#SalesForceExport.xls">
    <apex:pageBlock title="Opportunities">
        <apex:pageBlockTable value="{!account.Opportunities}" var="item"> //Plural Name
            <apex:column value="{!item.Name}"/>
            <apex:column value="{!item.StageName}"/>
            <apex:column value="{!item.Type}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>                          
</apex:page>

Thanks,
Kaushik
Javier Ramirez 10Javier Ramirez 10

Hi Kaushik,

In order to add it to the related list, the VF page has to be a standard list controller.

Please see the following: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_custom_button.htm?search_text=list%20button

With that, I have another issue. When I perform the export it attempts to export all the opportunities in the org, not just the ones on the related list.
I have the following code:
 

<apex:page standardController="Opportunity" recordSetVar="opportunities" contentType="application/vnd.ms-excel#Opportunities.xls">
    <apex:pageBlock title="Related Opportunities">
        <apex:pageBlockTable value="{!opportunities}" var="item">
            <apex:column value="{!item.Name}"/> 
            <apex:column value="{!item.RecordType.Name}"/>
            <apex:column value="{!item.Campaign_Name__c}"/>
            <apex:column value="{!item.StageName}"/>
            <apex:column value="{!item.CloseDate}"/>
            <apex:column value="{!item.Amount}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>                          
</apex:page>
 

All help is appreciated.

Thanks,
Javier