How to run SOQL Query on user or System mode?

 Salesforce Spring 23 release introduced a new feature USER_MODE.

What is a USER_MODE for SOQL Queries

By default salesforce runs SOQL queries in system context, with this new release spring 23, we can use USER_MODE to run SOQL queries on user context. here are the examples for how we can SOQL queries on user and system context. 

SOQL Query runs system mode:

Here is sample soql query on account object to run on system mode. It will return all the records in account. 
SELECT Id, Name FROM Account
also use following query to run system mode.
SELECT Id, Name FROM Account WITH SYSTEM_MODE

SOQL Query runs User mode:

Following soql query will run on current logged in user mode, and return records user has access.
SELECT Id, Name FROM Account WITH USER_MODE

Labels:
Join the conversation