I have a controller ControllerClassA which is with sharing. And i also have another class HelperClassB which is without sharing. I have a method inside a without sharing class HelperClassB which is called methodA.

I want to use this method inside with sharing class ControllerClassA with sharing applied.

please let me know if it is possible.


If you want a method that can be used from two different contexts with or without sharing applied, the right approach is to put that method in a separate class that is declared as "inherited sharing", then simply call that method from the classes that are with or without sharing as required. The method will then apply or not sharing rules.

public inherited sharing class WithOrWithoutSharing {
    public static void myMethod() {

public with sharing class WithSharing {
    public void somethingWithSharing() {
        // Will apply sharing

public without sharing class WithoutSharing {
    public void somethingWithoutSharing() {
        // Will NOT apply sharing
  • Thanks much.... i will apply the same – Sisir Apr 25 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.