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
Sonali GonnadeSonali Gonnade 

How to set APEX Controller in system mode

Hi,

 

We can execute APEX controllers in system mode or in User mode.

How to set particular APEX controller, controller extension classes or VF pages in System mode or in user mode.

Please help.

 

Thanks

Sonali

 

Best Answer chosen by Admin (Salesforce Developers) 
MandyKoolMandyKool

public class MyController{

 

//This class will run in system mode.

 

}

 

public with sharing class MyClass{

 

//This class will run in user mode.

 

}

 

Hope this helps..

All Answers

Ispita_NavatarIspita_Navatar

Generally if you don't explicitly specify apex executes in system mode.

If you define your classes using keyword "with sharing" it executes in user mode.

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

 

Sonali GonnadeSonali Gonnade

Thanks for your help.

Can you please share some sample example of how to define classes with keyword "with sharing".

It would be very much helpful to me.

 

Thanks

Sonali

MandyKoolMandyKool

public class MyController{

 

//This class will run in system mode.

 

}

 

public with sharing class MyClass{

 

//This class will run in user mode.

 

}

 

Hope this helps..

This was selected as the best answer
Sonali GonnadeSonali Gonnade

Thanks a lot.

MandyKoolMandyKool

You are most welcome!!!

 

If you need any help just post it.....