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

RageReference.getContent() failing on Spring '10 release

I have some apex code that has been running since winter '09 and it still works in Winter '10.  It consistently fails in Spring '10 

The apex code that invokes a visualforce page and then invokes a getContent method to retrieve the PDF that is created by the Visualforce page.    It consistently fails in Spring '10 with the following error

System.VisualforceException: core.apexpages.exceptions.ApexPagesGenericException:  


Has anyone seen this and have you figured out what to do? Here is a code snippet - it fails on the getContent.  I have not heard of any changes that are in Spring '10 that should cause this to fail.



PageReference pdfPage = new PageReference(Page.MyPage.getURL() + '?id=' + quoteId); System.debug('URL for attachment ' + pdfPage.getURL()); System.debug('create new attachment'); //create an attachment //Attach as an Attachment Attachment attachment = new Attachment(); attachment.ParentId = quoteId; = 'QuoteSent' +'.' + extension; attachment.body = pdfPage.getContent();





Like I have a problem, but I just created the code apex, which also uses the getContent method to retrieve a PDF file.

I debug and all I could find are these errors I hope you can help solve the case:



20100208225023.103:Class.ClassSendMail.tryTest: line 81, column 1: returning System.PageReference from method public System.PageReference send() in 4304 ms20100208225023.103:External entry point: returning from end of method static testMethod void tryTest() in 4808 ms




Resource usage for namespace: (default)Number of SOQL queries: 9 out of 100Number of query rows: 5 out of 500Number of SOSL queries: 0 out of 20Number of DML statements: 6 out of 100Number of DML rows: 6 out of 500Number of script statements: 90 out of 200000Maximum heap size: 804735 out of 1000000 ******* CLOSE TO LIMITNumber of callouts: 0 out of 10Number of Email Invocations: 1 out of 10Number of fields describes: 0 out of 10Number of record type describes: 0 out of 10Number of child relationships describes: 0 out of 10Number of picklist describes: 0 out of 10Number of future calls: 0 out of 10Number of find similar calls: 0 out of 10Number of System.runAs() invocations: 0 out of 20


 best regards.




These look like fairly normal messages from a test run.  What makes you think it is failing?  If you include your source and the error message I will have another look.
in particular the issue for me is to not let me move to production and sends me an error message...
internal Salesforce Error: 737787824-2763 (157541285)(157541285) 
Having the same problem in Spring 2010 - old code no longer passes tests and is blocking me from pushing live, but it all still works in production.  Also, I don't get errors when saving the visualforce page, it's just when running tests... I am just saving an HTML file and not converting to PDF, so I think it's happening in more than just the PDF case.
I'm running into the same problem with Spring 10.  This has to be an issue in Salesforce with the .getContent being invoked in a Test
I met my case the problem was not so much in development with the PDF `s but the method was tested as to many consultations, the tube that put in code so hard to reduce the consultations thus able to migrate .:smileywink:

I also get this error. We have a managed Package, and also a problem in test AND function. Everything was working fine in Winter'10



|FATAL_ERROR|System.VisualforceException: core.apexpages.exceptions.ApexPagesGenericException:





We found a solution for our problem



getContentAsPDF() instead getContent()


 It's working fine in testclasses and function.


I had this problem in tests but so far no problems when running the code normally.  Best thing to do is to add a try catch block around your code to catch System.VisualforceException so that the tests pass.  I think I remember coming across an article that stated that during tests the getContent() method would always return null - maybe it has something to do with this?
Message Edited by XactiumBen on 02-17-2010 03:57 PM
My experience is the same as yours.  I still have access to a Winter '10 environment.  I added some debugging code there and in a test run, the getContent does return a valid PDF.  So this is something new with Spring '10.  The try catch block is the best way to deal with it.  I am not familiar with the getContentPDF so I will have to try that as well.
Thanks for your post, it was timely!