1

When rendering a visualforce page as PDF, I'm running into the error above often and have been unable to figure out what the error is.

Through process of elimination, I have been able to narrow down the problem sections to my use of the datatable and columns tags, but can't figure out what the cause of the problem is. I read in the developer notes that you have to use datatable with caution and if a column is blank that could be the error, but I'm not sure if that is my problem. If anyone can take a look at my code and suggest any fixes, that would be great!

Below are the datatables that are causing the error message to fire:

                        <apex:dataTable value="{!Opportunity.opportunityLineItems}" var="OP" style="width:98.7%; border:1.5px solid #d9d9d9; border-bottom: 0px !important;">
                        <apex:column rendered="{!OP.TR_Service_Group__c = 'NQP'}" headerValue="TR Code" headerClass="column_ttl tac" styleClass="tbl_bdr tac" style="width:10%;"><apex:outputText value="{!OP.TR_Service_Group__c}"/></apex:column>
                        <apex:column rendered="{!OP.TR_Service_Group__c = 'NQP'}" headerValue="{!lblQty}" headerClass="column_ttl tac" styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OP.Quantity}" /></apex:outputText></apex:column>
                        <apex:column headerValue="Description" value="{!OP.PriceBookEntry.Name}" headerClass="column_ttl" styleClass="tbl_bdr" rendered="{!OP.TR_Service_Group__c = 'NQP' && Opportunity.Language__c = 'ENGLISH'}"></apex:column>
                        <apex:column headerValue="Description" value="{!OP.Product2.Product_name_french__c}" headerClass="column_ttl" styleClass="tbl_bdr" rendered="{!OP.TR_Service_Group__c = 'NQP' && Opportunity.Language__c = 'FRENCH'}"></apex:column>
                        <apex:column rendered="{!OP.TR_Service_Group__c = 'NQP'}" headerValue="Regular Price" value="{!OP.ListPrice}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;"></apex:column>
                        <apex:column rendered="{!OP.TR_Service_Group__c = 'NQP'}" headerValue="Sold Price" value="{!OP.UnitPrice}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;"></apex:column>
                        <apex:column rendered="{!OP.TR_Service_Group__c = 'NQP'}" headerValue="{!lblSubTot}" value="{!OP.TotalPrice}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;"></apex:column>
                    </apex:dataTable>          

                    <apex:dataTable value="{!Opportunity.opportunityLineItems}" var="OP" style="width:98.7%; border:1.5px solid #d9d9d9; border-top: 0px !important;">
                        <apex:column rendered="{!OP.TR_Service_Group__c = 'CNT'}" headerValue="TR Code" headerClass="column_ttl tac" styleClass="tbl_bdr tac" style="width:10%;"><apex:outputText value="{!OP.TR_Service_Group__c}"/></apex:column>
                        <apex:column rendered="{!OP.TR_Service_Group__c = 'CNT'}" headerValue="{!lblQty}" headerClass="column_ttl tac" styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OP.Quantity}" /></apex:outputText></apex:column>
                        <apex:column headerValue="Description" value="{!OP.PriceBookEntry.Name}" headerClass="column_ttl" styleClass="tbl_bdr" rendered="{!OP.TR_Service_Group__c = 'CNT' && Opportunity.Language__c = 'ENGLISH'}"></apex:column>
                        <apex:column headerValue="Description" value="{!OP.Product2.Product_name_french__c}" headerClass="column_ttl" styleClass="tbl_bdr" rendered="{!OP.TR_Service_Group__c = 'CNT' && Opportunity.Language__c = 'FRENCH'}"></apex:column>
                        <apex:column rendered="{!OP.TR_Service_Group__c = 'CNT'}" headerValue="Regular Price" value="{!OP.ListPrice}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;"></apex:column>
                        <apex:column rendered="{!OP.TR_Service_Group__c = 'CNT'}" headerValue="Sold Price" value="{!OP.UnitPrice}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;"></apex:column>
                        <apex:column rendered="{!OP.TR_Service_Group__c = 'CNT'}" headerValue="{!lblSubTot}" value="{!OP.TotalPrice}" headerClass="column_ttl tac" styleClass="tbl_bdr tar" style="width:15%;"></apex:column>
                    </apex:dataTable> 

                    <apex:outputPanel rendered="{!CONTAINS(strServiceType, 'PREPAID') && CONTAINS(Opportunity.Financing_Term__c, '36')}">    
                        <apex:dataTable value="{!Opportunity}" var="OPP" headerClass="hidden" style="width:98.7%; border: 1.5px solid #d9d9d9; border-top: 0px !important; border-bottom: 0px !important;">
                            <apex:column styleClass="tbl_bdr tac" style="width:10%;"><apex:outputText >HPX+HPS</apex:outputText></apex:column>
                            <apex:column styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OPP.TR_Prepaid_Unifon_Services_Qty__c}" /></apex:outputText></apex:column>
                            <apex:column styleClass="tbl_bdr tal" ><apex:outputText >Prepaid Services</apex:outputText></apex:column>
                            <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unif_n_Service_36__c}"/>  
                            <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unif_n_Service_36__c}"/>  
                            <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unif_n_Service_36__c}"/>  
                        </apex:dataTable>
                    </apex:outputPanel>

                    <apex:outputPanel rendered="{!CONTAINS(strServiceType, 'PREPAID') && CONTAINS(Opportunity.Financing_Term__c, '60')}">    
                        <apex:dataTable value="{!Opportunity}" var="OPP" headerClass="hidden" style="width:98.7%; border: 1.5px solid #d9d9d9; border-top: 0px !important; border-bottom: 0px !important;">
                            <apex:column styleClass="tbl_bdr tac" style="width:10%;"><apex:outputText >HPX+HPS</apex:outputText></apex:column>
                            <apex:column styleClass="tbl_bdr tac" style="width:5%;"><apex:outputText value="{0, number,###,###,##0}"><apex:param value="{!OPP.TR_Prepaid_Unifon_Services_Qty__c}" /></apex:outputText></apex:column>
                            <apex:column styleClass="tbl_bdr tal" ><apex:outputText >Prepaid Services</apex:outputText></apex:column>
                            <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unif_n_Service_60__c}"/>  
                            <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unif_n_Service_60__c}"/>  
                            <apex:column styleClass="tbl_bdr tar" style="width:15%;" value="{!OPP.TR_Prepaid_Unif_n_Service_60__c}"/>  
                        </apex:dataTable>
                    </apex:outputPanel>    

1 Answer 1

1

Please take a close look into the limitations of PDF generation in Visualforce pages documented here

If an <apex:dataTable> or <apex:pageBlockTable> has no <apex:column> components that are rendered, rendering the page as PDF fails.

To work around this issue, set the table component’s rendered attribute to false if none of its child apex:column components are rendered.

Hence make sure to not render the datatable if no apex:column components are rendered. For example, you can do below

 <apex:dataTable value="{!Opportunity.opportunityLineItems}" 
        var="OP" style="width:98.7%; border:1.5px solid #d9d9d9; border-bottom: 0px !important;"
   rendered={!Opportunity.HasNQPService__c} >

where HasNCPService__c is a formula field on Opportunity that is true if there is at least one opportunity line item that has TR_Service_Group__c = 'NQP'

10
  • OK I had a feeling it was something like that. With regards to the formula field though, I would need a roll up field first right?
    – Heather
    Jul 7, 2021 at 19:04
  • That's correct @Heather! You need roll-up and then use that to create another formula field. Jul 7, 2021 at 19:58
  • It's been awhile, but I'm still working on this. The suggestion above doesn't seem to be working. I have created a check box in my Opportunity labelled hasNQP and created a process it to check it when there is an NQP product in OLI. The test opportunity HAS NQP products, but even after I added the rendered qualification, it still is saying PDF generation failed.
    – Heather
    Sep 8, 2021 at 13:17
  • Here is what I did:
    – Heather
    Sep 8, 2021 at 13:17
  • <apex:dataTable value="{!Opportunity.opportunityLineItems}" var="OP" style="width:98.7%; border:1.5px solid #d9d9d9; border-bottom: 0px !important;" rendered="{!Opportunity.hasNQP__c = TRUE}">
    – Heather
    Sep 8, 2021 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.