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
Soul AgesSoul Ages 

Can't search user unique field in tests

After having most test failed suddenly for no apparent reason, we found that the culprit was that a field we were using to search for a special user was changed to be unique. 

User[] users = [select id from User where Unique_Field___c = :'Special' limit 1];
System.assert(users.size()>0, 'Missing Special user configuration.');

 If I run the code in a test method, I get 'Missing Special user configuration.' assert exception. If I run it in a developer console, it runs without the assert triggering.

Any ideas why is this? Is it a bug or feature? Is it documented anywhere?

juan.cardonajuan.cardona

Hi

 

Have you put the  "seeAllData" condition in the Test Class?

 

Like this:  @isTest(seeAllData=true)

 

 

Soul AgesSoul Ages

No, but according to this users are still visible in tests. And if I remove the unique property from the field, the test works.