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
davcondevdavcondev 

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?

sfdcfoxsfdcfox
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).