title: How to get query covered in apex test class for salesforce
body: <p>I'm having a tough time trying to get all code covered in my test class for an apex class.</p>
  
  <p>Apex class:</p>
  
  <pre><code>public with sharing class myclass {
  
  **public List&lt;CustomObject1&gt; listvar {get;set;}**
  
  public myclass(ApexPages.StandardController sc){
      CustomObject2 var = [SELECT Id, Field1__c FROM CustomObject2 WHERE Id = :ApexPages.currentPage().getParameters().get('id')]; 
      **listvar = [SELECT Id,Name,Field1__c,Field2__c,Field3__c,Field4__c,Field5__c,CreatedDate,CreatedById FROM CustomObject1 WHERE Field2__c = :var.Field1__c ORDER BY CreatedDate DESC];**
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Test Class:</p>
  
  <pre><code>@isTest
  public class myclass_Test {
  
       static testmethod void dosomething(){
  Account a = new Account();
              a.Name = 'Test acct';
              insert a;
  
          CustomObject4__c v = new CustomObject4__c();
              v.Field1__c = '123 ABC';
              v.Name = 'test name';
              v.Field2__c = True;
              v.Account__c = a.Id;
              insert v;
  ... more record creates including ones for the object being queried...
  
  PageReference pageref = Page.myVFpage;
      Test.setCurrentPageReference(pageref);
      ApexPages.StandardController sc = new ApexPages.StandardController(v); 
  
          myclass myPageCon = new myclass(sc);
  }
  }
  </code></pre>
  
  <p>I've tried creating a new list for the underneath the last line in the test class and populating the list, but I cannot get 100% code coverage. I marked the lines that I'm not getting any coverage from the test class with. Any suggestions?</p>