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
niraj kumar 45niraj kumar 45 

Soql Fetches data in which mode

I have an object with 40,000 records. There are 2 user one is Admin user and other is user Mode user.
The user mode user has access to only 10,000 records whereas admin user has access to all the 40,000 records.
If I run my SOQL query with Sharing in Apex class then my Soql will first look in all the 40,000 records and then it will give me 10,000 records which he has access to it or it will directly run on only 10,000 reords to which he has access?

 
v varaprasadv varaprasad
Hi Niraj,

 The with sharing keywords when declaring a class to enforce the sharing rules that apply to the current user.

EX :
public with sharing class TestSoqlInWithSahring {
    
    public static void display(){
        integer lstAccssize = [SELECT count() FROM Account];
        system.debug('===lstAccssize==='+lstAccssize);
    }

}

Here it will directly run on only 10,000 reords to which he has access,

Thanks
Varaprasad
Prafull G.Prafull G.
Apex Class with Sharing will return only 10000 records where User have access.