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
indranily81indranily81 

test class in version 24 can not access AccountShare.

Hi,

 

Recently I was trying to query AccountShare record through test class for one of my projects. The data is prepared in test class itself but the query could not fetch any record when fired from the particular user context. I am always getting 0 rows within the System.runAs context.

 

Once I downgraded both the test class and target class to v23 it worked.

Are the sharing tables for the standard objects not exposed in v24, if queried from specific user context ?

 

 

Thanks

Indranil

 

 

 

 

SeAlVaSeAlVa

Have you tried quering Account Object? 

If you try, you will probably notice that there is nothing to query (0 results, unless you insert something in the testMethod ).

 

This is one of the changes performed in Spring 12. If you want to access all data created outside your test method context, you will need to use seeAllData parameter for @IsTest notation.

 

See the example below.

@isTest(SeeAllData=true)
public class TestClassName {
  // your methods here, all of them can query all data in the organization.
}

// or

@isTest
private class ClassWithDifferentDataAccess { 
    @isTest(SeeAllData=true)
    static void testMethodName() {
        // Can query all data in the organization.        
    }
}

For more information

 

Regards,

 

 

 

indranily81indranily81

Thanks SeAlVa for the quick response.

 

Yes Account is accessible from the test method. The problem is with the sharing table associated with Account. I have already stated that all the test data is created within the test method hence I don't see a reason for seeAllData. We setup our test data in such a way that it should never match with any real data. More over our customer have very strict policies regarding data visibility so we can not even use that annotation in production as in that case all data will be exposed. We don'i want that to happen.

 

Hope my question is making sense.

 

Regards,

Indranil