I have created getContent() method to send a pdf page in email using Visualforce page. But while running test method on the controller, I am getting following error message - "Methods defined as TestMethod do not support getContent call, test skipped" How to fix this problem. Thank you in advance.


There's a few ways to do this. My personal preference is to generate a different Blob for the body of the page depending on whether my code is running in the test context:

So if I have a reference to the page in variable pr:

   Blob content;
   if (Test.IsRunningTest())

and then do whatever I need to do with the body content.

  • 18
    I'd suggest making it a one-line for test coverage purposes. Something like: Blob content = Test.isRunningTest() ? Blob.valueOf('UNIT.TEST') : pr.getContent(); That way, it'll cover if you could get the content or not. – Programmable Medley Mar 9 '15 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.