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

Test Coverage on Controller method



     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(''+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. = 'household.pdf';
 attpdf.ContentType = '.pdf';
 insert attpdf;
 return null;







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:



      attpdf.body = pdfpage.getcontent(); 


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