+ Start a Discussion
SFDC_LearnerSFDC_Learner 

User and system mode

Hi

 

Apex Sharing Class:

 

public with sharing class TestCls {

    public TestCls(){

         myweb.dologic();

   }

}

 

=====

// Webservice class

 

Global class className{

    dologic();

}

 

 

 

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

Hi,

 

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.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_keywords_sharing.htm

 

 

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

 

Thanks,

 

Prashant Tiwari

 

 

Ashish_SFDCAshish_SFDC

Hi , 

 

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

 

Is the class wrtiing for testing the code?

 

Regards,

Ashish

sfdcfoxsfdcfox
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:

http://salesforce.stackexchange.com/questions/16121/sfdc-understanding-with-sharing-without-sharing-unspecified-sharing-classes

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