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
sonatinesonatine 

error "System.VisualforceException" at .getContent()

hey guys, i get this error all of the sudden.

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

Class.GenerateAttachEmailCertificate_WS.GenerateAttachEmailCertificate: line 10, column 18
Class.GenerateAttachEmailCertificate_WS.testingEmail: line 93, column 14
External entry point".

 

line 9 and 10:

 

PageReference pdf = new PageReference('/apex/CertificatePrintToPdf?id=' + id); Blob pdfBody = pdf.getContent();

 

and line 93 is inside my test method:

 

testSend = GenerateAttachEmailCertificate_WS.GenerateAttachEmailCertificate(testId, testVer, testLoc);

 

im pretty sure it was 100% coverage, but now im in the middle of deploying a new class into production, and i got that error.

 

can anyone help me please?

thanks in advance.

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

When did you last try?  This should be working correctly as of last night/this morning. 

 

If there is still a problem you will need to file a case.

 

Note that "correctly" means that for version 17 and earlier any errors in generating the page for getContent() are ignored, possibly returning an error page or other unexpected result from the getContent() call.  For version 18, they will generate an exception in the controller or test method that calls getContent()

Message Edited by aballard on 03-11-2010 05:21 PM
Message Edited by aballard on 03-11-2010 05:54 PM

All Answers

JEndoJEndo
I am also experiencing this issue and it is preventing me from deploying a breakfix to Production.  Please advise ASAP.  This is a bug with getContent() in the Spring '10 Release.
aballardaballard

Two questions:

1) what salesforce instance (na1, na2, etc.) is your organization on?

 

2) what api version is you page set to?  If it set to 18, you might try changing it to 17 and seeing if the test then passes.

There was a change in the error handling for version 18... prior to that, errors in getContent were quietly ignored.... so it might have been failing along but you didn't know it.

mcrosbymcrosby

I am also experiencing this issue.  I tried deploying some code changes this afternoon to a VisualForce extension, but the IDE is reporting an error in a separate class that involves using the getContent() call.

 

The offending class has an api version of 14, the production instance is on na4, and no change has been made to that class in a long time.

PageReference pdfPage = new PageReference('/apex/TripExport?id=' + trip.Id); Blob pdfBlob = pdfPage.getContent(); //<-- error reported here

 


Message Edited by mcrosby on 03-09-2010 03:12 PM
sonatinesonatine

anyone?

 

ive tried to change to it to version 17, still displaying the same error.

 

aballardaballard

When did you last try?  This should be working correctly as of last night/this morning. 

 

If there is still a problem you will need to file a case.

 

Note that "correctly" means that for version 17 and earlier any errors in generating the page for getContent() are ignored, possibly returning an error page or other unexpected result from the getContent() call.  For version 18, they will generate an exception in the controller or test method that calls getContent()

Message Edited by aballard on 03-11-2010 05:21 PM
Message Edited by aballard on 03-11-2010 05:54 PM
This was selected as the best answer
aballardaballard
Also note it is the version of the controller or testmethod that calls getContent() that matters, not the version of the page being accessed by getContent()
JerryHJerryH

Same here.  This was working perfectly before 1400 PST, and suddenly all my unit tests and whatnot are failing.

 

So if PageReference.getContent() is broken what should I replace it with?

 

Jerry (Not A Happy Camper) H.

 

aballardaballard

Nothing has changed lately.  The messages above are from 6 weeks ago.   It is working AFAIK. 

Perhaps you just changed the version of your page or controller?   That would change how it behaves, as described above.

JerryHJerryH

The version #'s for the controllers haven't changed, but I *did* try to go from an unmanaged package to a managed package. :-?

 

Here are the lines of code that (apparently?) are failing:

 

        PageReference page = new PageReference('/resource/1271867704000/testOpportunityLineItem');
        dom.Document doc = new dom.Document();
        doc.load(page.getContent().toString());

 

And the exception:

 

       core.apexpages.exceptions.ApexPagesGenericException:
       External entry point

 

Luckily I had already pushed the entire (unmanaged, pre-assigning-a-namespace) package to another account at SalesForce, and from there the unmanaged version of the code is working like a charm.  But now that I've assigned a namespace (etc.) the code is failing whenever I'm calling a line in the test code (or real code) that parses the HTML response object into the DOM tree.

 

Again, let me point out that the exact same version of the application -- minus the namespace -- is working fine on another SalesForce account page.  But something seems to have flown south now that I want to try putting together a managed package for client beta testing.

 

Jerry (Very Much ARGH!) H.

aballardaballard

Sounds like something quite different.   You should file a case. 

 

P.S. ... you should be usinmg  $Resource.testOpportu nityLineItem  not the reverse-engineered /resource/... url, which is likely wrong. 

 

 

JerryHJerryH

[insert partial smack-alongside-the-head for Jerry]

 

Going to a managed package apparently (invisibly?) updates all of the code behind the scenes to use the package (namespace) name followed by the *double-underline*.  So the following unit test code now works like a charm:

 

        PageReference page = new PageReference('/resource/1271867704000/Nexternal_testOpportu nityLineItem');
        dom.Document doc = new dom.Document();
        doc.load(page.getContent().toString());

 

Btw, I've tried to figure out what you mean by $Resource, but so far I can't find anything about how this works from the Apex Controller... mostly because Google and the SalesForce search control "helpfully" strip off the dollar sign. :-|

 

Is there a specific forum link or PDF document that gives an example of how to use (something like?) "$Resource.testOpportunityLineItem" from within the Apex Controller test class?

 

(And thanks for the help, btw.  Much appreciated, owe you a beer! :-))

 

Jerry (Slightly Less Angry, But Not By Much*) H.

 

* == If adding the namespace breaks my code, they bhy ghod *REFORMAT MY CODE ON SALESFORCE*.  And by "reformat" I mean *ADD PACKAGE [your namespace] AT THE TOP OF THE CODE* or do something like "pubilc class [namespace]__MyClassName" in each CLS file!  ARGH!  Argh, argh, argh, ARRRRRRRRGGGGGHHHHH!!!!

aballardaballard

Sorry, you are right, $resource syntax does not work in apex code, only in pages.    Don't think there is an official way to generate a pagereference to a static resource.   (You might want to suggest that in ideas).

 

When you reverse-engineer undocumented salesforce urls you take a chance on it changing on you.

(As it does in this case when you go from unmanaged to managed.    The number following /resource/ will also change everytime you update the static resource. ) And the syntax might change from one release to another....

 

 

AkiTAkiT

I started to get similar error when I packages my application. My test class and controller are api version 18.

 

 

PageReference p = Page.EventPrintoutPdf;
p.getParameters().put('id', e.Id);
Blob pdfBlob = p.getContent();
PageReference p = Page.PdfPage; 
p.getParameters().put('id', e.Id); 
Blob pdfBlob = p.getContentAsPdf();  // This line results in error

 

 

The error I get is:

 

Internal Salesforce Error: 809768074-2240 (1901879687) (1901879687)

 

 

If I screw down the api to 16, it will work but then Adobe complains about decoding issue and cannot open the PDF.

 

I am stuck, seems there is system error somewhere. I have filed a case but no response..