You need to sign in to do that
Don't have an account?
Michael Paulson
pageReference.getContentAsPDF losing view state
I'll try to keep this simple as I suspect the answer might be something where there is a known workaround, but I just can't find that.
I am accepting input from the user and kicking it out in a PDF. This is being done through an iFrame (I'm also using the same code to save a PDF). So the relevant parts are below:
Apex:
Visualforce:
I'm letting the user add and remove rows of data and I'm confident I am doing this correctly because I have traced the error to a particular variable and am running debug lines on that variable right before the problem line (above). When adding a new row and saving, the debug shows the variable equaling what it should (0,1,2,3,4,5), but when I save and kick out the PDF, I am getting a 'Subscript value 6 not valid. Must be between 0 and 5' error. It is also working if I comment out the getContentAsPDF line and display the page directly rather than through an iFrame (but I need to do this for a couple reasons). Is there a known issue and workaround having to do with the getContentAsPDF method that I should be aware of?
Sorry to be vague, and let me know if more of my code would help, but I'm assuming, given the above reasoning, that the issue is related to some Apex quirk rather than something I'm doing incorrectly. Thanks in advance!
I am accepting input from the user and kicking it out in a PDF. This is being done through an iFrame (I'm also using the same code to save a PDF). So the relevant parts are below:
Apex:
PageReference ref = Page.myPDF; ref.getParameters().put('id', account); Blob contentData = ref.getContentAsPDF(); //THIS LINE IS WHERE THE PROBLEM COMES IN pageRefPDF = 'data:application/pdf;base64,' + EncodingUtil.base64Encode(contentData);
Visualforce:
<apex:iframe id="frame" src="{!pageRefPDF}"/>
I'm letting the user add and remove rows of data and I'm confident I am doing this correctly because I have traced the error to a particular variable and am running debug lines on that variable right before the problem line (above). When adding a new row and saving, the debug shows the variable equaling what it should (0,1,2,3,4,5), but when I save and kick out the PDF, I am getting a 'Subscript value 6 not valid. Must be between 0 and 5' error. It is also working if I comment out the getContentAsPDF line and display the page directly rather than through an iFrame (but I need to do this for a couple reasons). Is there a known issue and workaround having to do with the getContentAsPDF method that I should be aware of?
Sorry to be vague, and let me know if more of my code would help, but I'm assuming, given the above reasoning, that the issue is related to some Apex quirk rather than something I'm doing incorrectly. Thanks in advance!
Not sure what is wrong in your code but after some research, I found below links see if that can help you.
http://stackoverflow.com/questions/8633323/error-subscript-value-9-not-valid-must-be-between-0-and-8
http://salesforce.stackexchange.com/questions/132756/getting-error-content-cannot-be-displayed-subscript-value-5-not-valid-must-be
http://salesforce.stackexchange.com/questions/125890/stop-increment-of-apex-variable
https://developer.salesforce.com/forums/?id=906F000000097hMIAQ
Hope this helps you!
If this helps you please mark it as solved so that it will be ava
Thanks and Regards
Sandhya