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
Megan Moody 10Megan Moody 10 

unit test query list has now rows

I am trying to write a unit test that tests the apex class used by a VF page. My list is returning no items even though my query should be valid. 

The system.debug statement shows that the ID for the contact does exist. Any ideas why my query (right below the system.debug line at the top) is returning no rows? 
System.runAs(testUser){
            system.debug('objContact ID ' + objContact[0].id);
            Contact firstContact = [SELECT ID, firstname, Subscriber_ID__c, Member_ID__c 
                                    FROM Contact 
                                    WHERE ID = :objContact[0].id];
            ConciergeDisplayFamilyMembers testFamily = new ConciergeDisplayFamilyMembers(new ApexPages.StandardController(firstContact));
            ApexPages.StandardController sc = new ApexPages.StandardController(firstContact);
        	Contact primaryContact = testFamily.currentContact;
        	System.assertNotEquals(null, primaryContact);
        }
KaranrajKaranraj
Megan - Make sure that runAs user in your test class have access to contact object. ('testUser')
doravmondoravmon
Are you sure the objContact[0].Id is the ID in the query ?