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
Alice JuAlice Ju 

Need help in increasing test coverage

Hi there,
I'm really new to apex and visual force page, and I'm trying to meet the 75% test coverage bar to deploy my VS page. I'm stuck in how to increase the test class now. Take the trigger below for example, the two lines that I mark as bold is marked as "not covered" in the developers console. And these two lines won't fire off any trigger, so I really don't know how to write a test class for code like this. Can any one be so kind and give me some advise? Thank you!


List<Opportunity> AllClosedOp= [SELECT AccountId, Id,Invoiced_Date__c, Renewal_Due_Date__c, CloseDate
    from Opportunity where AccountId in :accountIds and (StageName='Closed Won' OR StageName='Closed Won Waiting for invoice')];
    List<Contact> AllContact=[Select Id, AccountId, Contact_Role__c From Contact where AccountId IN :accountIds and Contact_Role__c!=Null];
   
    For(Opportunity opt:AllClosedOp)
    {   
     ClosedWonOps.get(opt.AccountId).add(opt);    
    }
    For(Contact ct:AllContact)
    {
     AccountContacts.get(ct.AccountId).add(ct);
    }
Satish_SFDCSatish_SFDC
You should create some test data which will match the queries you have written at the top.

In that case the query returns some data and control goes into the loop. This way the two lines will be  covered.

You mentioned that these two lines do not fire off any trigger. How is this code executed and what other code calls this code?

Regards,
Satish Kumar