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
bharath kuamarbharath kuamar 

please help me with this test class for below class coverage increase

Hi, i have written the test clss for the below class but the coverage shows only 60%, please help me to increase the coverage

global class PDFGencontroller
String LongDate = ' ';
String hostUrl;
String PreferId=System.currentPagereference().getParameters().get('id'); 
public PDFGencontroller()
 hostUrl = 'https://'+ ApexPages.currentPage().getHeaders().get('Host') +'/servlet/servlet.FileDownload?file=';

public list<contact> getcontactinfo()
    system.debug('<<<<<<<<<<<<<Inside getContactInfo>>>>>>>>>>>>>>'+PreferId);
    List<Contact> con = new List<Contact>();
    Preference__c  p=[select opportunity__c from preference__c where id=:PreferId];
    OpportunityContactRole oRole = [Select ContactId from OpportunityContactRole Where OpportunityId=:p.opportunity__c ];
    con =[select firstname,lastname,Birthdate,Email,Phone from contact where id=:oRole.ContactId];
    return con;

 public list<Preference__c> getPreferenceInfo()
    List<Preference__c> con1 = new List<Preference__c>();
    con1=[select name,Payment_Modes__c,payment_frequency__c,duration__c  from preference__c where id=:PreferId];
    return con1;
   public list<commitment__c> getCommitmentInfo()
     List<commitment__c> con2 = new List<commitment__c>();
    con2=[select name,Commitment_Type__c,Start_Date__c,End_Date__c,status__c from commitment__c where preference__c=:PreferId];
    return con2;
 public list<Payment_Schedule__c> getPaymentInfo()
    List<Payment_Schedule__c> con3 = new List<Payment_Schedule__c>();
    Preference__c p=[select opportunity__c from preference__c where id=:PreferId];
    con3=[select name,Payment_Start_Date__c,Payment_End_Date__c,Payment_Frequency__c,Payment_Mode__c,Amount__c  from Payment_Schedule__c where Opportunity__c =:p.opportunity__c ];
    return con3;

    public String getLongDate()
        Datetime cDT =;
        LongDate = cDT.format('MMMM d,yyyy');
        return LongDate;
      //test methods for the class "PDFGencontroller"
  static testmethod void PDFGencontroller()
        PDFGencontroller pdfn = new PDFGencontroller();
        String hostUrl='_https://'+ 'ER201109-0000570' +'/servlet/servlet.FileDownload?file=';
        Preference__c pref = new Preference__c();
        insert pref;
        //OpportunityContactRole oRole = new OpportunityContactRole();
        //oRole.ContactId ='0039000000CvOJa';
       // insert oRole;

        Contact con = new Contact();
        con.Phone ='6262323';
        insert con;

        Preference__c con1= new Preference__c();
        con1.payment_frequency__c='Annually(Full Payment)';
        insert con1;
        commitment__c comm = new commitment__c();
        comm.Commitment_Type__c='Sponsor a child';
        insert comm;
                 //  pdfn.getPaymentInfo();  
        Payment_Schedule__c payy =new Payment_Schedule__c();
                  // payy.getPaymentInfo(); 'ghd';;
             insert payy;

       Preference__c con11= new Preference__c();
       insert con11;
       Payment_Schedule__c payment = new Payment_Schedule__c();'testpayment';;;
         insert payment;
        // pdfn.getPaymentInfo();

getPaymentInfo() method and getcontactinfo()method is not covered, please help me out


Jerun JoseJerun Jose
The two methods are not being covered because the two methods are not called.

I see that you have commented the calls to those methods. All you will need to do is to uncomment the calls.
bharath kuamarbharath kuamar

i tried to call these two mtehods , but giving a test failture

Jerun JoseJerun Jose
Then you will have to fix those failure reasons. Not calling them will not give you code coverage.
Face your fears :P

... or delete the methods if they don't work.  ;-)