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
CloudHugger2CloudHugger2 

contentAsPDF renders the wrong page

Hi All,

 

Simple, consistent issue - and no feedback from Salesforce via the partner portal in weeks. Hoping others may have seen this.

 

The following simple logic has me stumped and is consistent in its results.

 

Assume user calls the following via a commandbutton that is on Page A:

 

PageReference p = Page.B;
p.getParameters().put('id', <someid>);
Blob b = p.getContentAsPdf();
attachment a = new attachment(parentid = ..., body = b, name = 'test.pdf');
insert a;

 The attachment ends up a render of Page A, the current page user is looking at, NOT page B as you'd expect.

 

Has anyone else experienced this? I have two totally different environments producing the same outcome described above consistently.

 

Cheers,

CloudHugger

 

Best Answer chosen by Admin (Salesforce Developers) 
CloudHugger2CloudHugger2

Righto - solved this one.

 

I was sharing the controller across both pages A and B, so the view state was persisting.  Once I created a controller specific to the page I was trying to render things became more predictable.