+ Start a Discussion

User and system mode



Apex Sharing Class:


public with sharing class TestCls {

    public TestCls(){






// Webservice class


Global class className{






In this case What is the apex code execution mode. is it in user / system?



Because all webservices will execute in system mode. But sharing class will execute in user mode.


When we call a webservice method from sharing class.. what is the final execution mode?

Prashant TiwariPrashant Tiwari



Final execution mode will be System mode As you are calling a method which is defined in Web Service.


The sharing setting of the class where the method is defined is applied, not of the class where the method is called. For example, if a method is defined in a class declared with with sharing is called by a class declared withwithout sharing, the method will execute with sharing rules enforced.





mark it as solved if the solution worked as it might help others..!!




Prashant Tiwari




Hi , 


As Webservice class is the one which executes it will run in System mode.


Is the class wrtiing for testing the code?




The function will execute "with sharing" when called from the class. Just because a class is a "web service" class doesn't mean it always runs in "web service" mode. See this link for a more detailed answer:


In short, if you don't specify sharing, the calling class gets to choose if sharing is applied or not.