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
sunny@99-chgsunny@99-chg 

Test Coverage on Controller method

Hai,

 

     I have small issue regarding Test Coverage for a method,below is the code,

 

When I am calling this method through test coverage,it is covering partially. Remaining how to cover can any one tell me. see below comments

 

        public pagereference household(id leadid)

{
 
 pagereference pdfpage = new pagereference('https://c.cs9.visual.force.com/apex/household?leadid='+leadid);
attachment attpdf = new attachment();
 attpdf.parentid = leadid;                      // Upto here the code is covered.
 attpdf.body = pdfpage.getcontent();  // from here the code is getting struct and not covering the remaining code.
attpdf.name = 'household.pdf';
 attpdf.ContentType = '.pdf';
 insert attpdf;
 return null;

}

 

 

Thanxs,

Sunny.

vishal@forcevishal@force

Test coverages don't support getContent() and getContentAsPDF() methods as of now.

 

Since this is a straightforward limitation, you can add a condition above your statement where you're calling this method:

 

if(!Test.isRunningTest())

      attpdf.body = pdfpage.getcontent(); 

 

* You will call this method only when the apex code is NOT CALLED FROM A TEST COVERAGE.