22

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.

1 Answer 1

32

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())
   {
        content=Blob.valueOf('UNIT.TEST');
   }
   else
   {
        content=pr.getContent();
   }

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

1
  • 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. Mar 9, 2015 at 13:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .