2

I have a visualforce page (a letter menu) that on the click of a button (downloads a PDF and saves a letter to the record):

<apex:commandButton action="{!saveLetter}" value="Download Letter"/>

Runs some apex which includes a controller extension with:

pageReference pdf = Page.visualforce_detail_page;
system.debug(pdf);
pdf.getParameters().put('id',wo.ID);
return pdf;

This then displays the "visualforce_detail_page" that only includes a standard controller. On this page I have some fields like:

<apex:page standardController="WorkOrder" renderAs="PDF"  showHeader="false" >
  {!workorder.workordernumber}
  {!workorder.address_line_1__c}
 </apex:page>

If I was to view this page directly from the Case Detail page it works as expected, so does typing in the url manually. However if I try and open the detail visualforce from the 1st one it produces the error:

standard SObject row was retrieved via SOQL without querying the requested field: address_line_1__c

What I don't understand is why it works from the detail page, as I would expect, but it doesn't work when called from the visualforce page and the ID passed with it? The only field I have been able to get to work is "WorkOrderNumber"...

P.S I was hoping the "letters" whilst all called from the "letter menu" don't need custom apex. I wanted to use the standard controller, to save a bit of time and work tbh.

1

1 Answer 1

0

I found a workaround for this and I don't fully understand why it is required when both visualforce pages use the same standard controller but here it is:

On the first visualforce page you must include all of the fields that are displayed on the second visualforce page. I have hidden them in a div like this:

.hidden{
    display: none;    
}


<div class="hidden">
     {!workorder.Address_Line_1__c}
     {!workorder.Address_Line_2__c}
     {!workorder.Address_Line_3__c}
     {!workorder.Address_Line_4__c}
     {!workorder.Address_Post_Code__c}
</div>

Then on the second visualforce just copy the fields on as normal and it works for me:

{!workorder.Address_Line_1__c}
{!workorder.Address_Line_2__c}
{!workorder.Address_Line_3__c}
{!workorder.Address_Line_4__c}
{!workorder.Address_Post_Code__c}

Apologies for some mistakes in the question, in the end the 1 line of code that was causing the problem was the getContentAsPDF() but the above resolved the issue.

You must log in to answer this question.

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