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
Padmini Sidugonde 6Padmini Sidugonde 6 

Not able to cover method variable in test class

Hi,

I have below apex class which i am not able to cover in test class.
public class createdoc
{  
public PageReference CreateDocument()
    {
                   product pr = [select id, Limited_Company_App_Form__c from product where id=:opp.product__c];
            docsetting sett = new docsetting (pr.Limited_Company_App_Form__c );                         
            string body= sett.Calldoc(opportunityId);   
              
            if(sett.AttachmentId != null)
            {
                Opp.Attachment_App_Form__c = sett.AttachmentId;
                update opp;
                           } 
               
        
        return null;
    
 }       
    }

 
mukesh guptamukesh gupta
Hi Padmini,

Please share your test class code.

Regards
Mukesh
 
Madhukar_HeptarcMadhukar_Heptarc
Hi Padmini,

can you try below code in your test class 

        createdoc docReference= new createdoc(new ApexPages.StandardController(new Object_Name()));
        docReference.CreateDocument();

(or)

Can you please provide the full code of apex class and Visualforce Page so that it is easy to resolve.

Please let me know if any help required.

Thanks & Regards 
Madhukar_heptarc

 
Tad Aalgaard 3Tad Aalgaard 3
I, like mukesh gupta would also like to see what you have written so far for your test class.  I would like to see if you have attempted to write your test class or if you are asking us to write the entire thing for you without having even tried.  Too many posters on this site ask for everyone to write their test classes for them.  If you can show that you have attempted to write the test class we will gladly help you if you are stuck.
Padmini Sidugonde 6Padmini Sidugonde 6
Hi Mukesh and Tad,

This is my test class. Here docsetting  class is other helper apex class. I have tried but not covering the helper class. 

Thanks in Advance.
@isTest 
public class createdoc_Test
{
 @TestSetup
static void setup()
{
docsetting__c conga = new docsetting__c();
    conga.Name = 'test conga';
    insert conga;
   Product__c prod = new Product__c();
    prod.Name = 'test product';
    prod.Limited_Company_App_Form__c = conga.Id;
    insert prod;
   Opportunity o1 = new Opportunity();
    o1.Name = 'Test opportunity';
    o1.product__c = prod.Id;
    o1.Attachment_App_Form__c = 'test data';
    insert o1;
}

  static testMethod void createdocmethod() 
 {

 Product__c p = [select id,Name,Limited_Company_App_Form__c  from Product__c ];
 Opportunity o = [select Name,product__c,Attachment_App_Form__c from Opportunity ];  
createdoc cd = new createdoc();
cd.CreateDocument();
cd.opportunityId = o.Id;
}
}