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
nishwalnishwal 

@isTest(SeeAllData=false) annotation not working

 If @isTest(SeeAllData=false) working for anyone?

I have annotated the class as well as the method but the testmethod can see the existing data.

Here is simple code snippet. Assertion is getting failed for me...

@isTest(SeeAllData=false)
private class testAnnotationSeeAllData {

static testmethod void myUnitTest()
{
Test.startTest();
List<User> lstUsers = [Select Id, Name From User Where IsActive= true Limit 100];
System.assert(lstUsers.size() == 0);
Test.stopTest();
}
}

tried in api version 24 and 25 both. and Developer Org and Sandbox.


is there anyone who is experiencing the same problem?

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Users aren't considered data for this purpose.  The following doc page:

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_data_access.htm

 

details which data will still be visible to your test - user is on that list.

All Answers

bob_buzzardbob_buzzard

Users aren't considered data for this purpose.  The following doc page:

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_data_access.htm

 

details which data will still be visible to your test - user is on that list.

This was selected as the best answer
Dan Blackhall.ax1171Dan Blackhall.ax1171

Hi Bob,

I don't know if you'll still read this, but I have a case (08933438 and 08943094) about a bug with seeAllData I think I have found. Two tests doing exactly the same this, one has see all data and passes, the other does not and fails.

 

@IsTest
private class SFDCTestSeeAllDataBug {

	@IsTest(seeAllData=true)
	private static void testSeeAllDataCorrectBehaviour() {
		Project__c project = new Project__c(Name='SeeAllData True Project');
		insert project;
		Work__c subscription = new Work__c(
			RecordTypeId = RecordTypeHelper.workSubscription.Id,
			OwnerId = UserInfo.getUserId(),
			Project__c=project.Id
		);
		insert subscription;
		
		Work__c queryedSubscription = [
			SELECT
				Id,
				Project__c,
				Owner.IsActive
			FROM
				Work__c
			WHERE
				Owner.IsActive = true
				AND Project__c = :project.Id
		];
		System.assert(queryedSubscription.Owner.IsActive);
	}

	@IsTest(seeAllData=false)
	private static void testSeeAllDataBug() {
		Project__c project = new Project__c(Name='SeeAllData False Project');
		insert project;
		Work__c subscription = new Work__c(
			RecordTypeId = RecordTypeHelper.workSubscription.Id,
			OwnerId = UserInfo.getUserId(),
			Project__c=project.Id
		);
		insert subscription;
		
		List<Work__c> queryedSubscription = [
			SELECT
				Id,
				Project__c,
				Owner.IsActive
			FROM
				Work__c
			WHERE
				Owner.IsActive = true
				AND Project__c = :project.Id
		];
		System.assertEquals(1, queryedSubscription.size());
	}
}

 Could you confirm this is expected behaviour (as support is claiming). Because it doesn't look like to to me.

Mitesh SuraMitesh Sura
How about "AdditionalNumber" standard object? I do not see that in the list but it would still return data with (SeeAllData=false) attribute??