+ Start a Discussion

runAs vs "without sharing" - who wins?

A test method uses runAs to apply some restrictive sharing rules applied to a particular user. However the class being executed by the test method is "without sharing".


I thought sharing rules would be ignored, but they weren't. Is this correct?

Runas effectively sets $User.Id (the current running user) to the named user. It has no effect on "with sharing" or "without sharing" behavior directly-- in other words, "without sharing" should still operate without consideration for user share permissions.

Perhaps you could elaborate on what you've done. Either you've got a bug on your hands, you've written a faulty test, or the code itself isn't written correctly (could be any of the three, hard to tell without code to reproduce).