I'm facing a scenario that I believe it is related to some permission that's missing.

I'm calling a invocable method that is called by a Record Triggered flow that doesn't return records, here is the scenario:

  • a public VisualForce is called
  • it inserts a record in a custom object
  • this custom object has a record triggered flow that's called by a entry condition according to the insert
  • inside the record triggered flow, theres a call of an invocable method
  • inside the invocable method, it calls a helper class that needs to query another custom object

The issue: All the time this query comes empty.

But, if I call the same invocable method via Developer console, it runs as expected. (Here, I'm using admin user)

If I try to query the custom object in the same visual Force controller that starts the transaction, that is, by using the same user that calls all the process, it can query the custom object.

What permission would be missing that's avoiding the helper class (called by invocable method) to access the records of the custom object?

Here is the call hierarchy:

  • VisualForcePageController = without sharing
  • A record is created
  • This creation calls a Record Triggered flow, time based
  • A subflow is called
  • InvocableClass = with sharing (1st level)
  • Helper class = with sharing (2st level)
  • SubHelper class = with sharing (third level) => Here is the issue

EDIT: adding a Code snippet

global class with sharing InvocableClass 
  public static List<MyCustomObject> getRecord(List<MyWrapper> data) 
     List<MyCustomObject> dataToReturn = Helper.getRecords(data.get(0).myField);
     return dataToReturn ;

class without sharing Helper 
   public static List<MyCustomObject> getRecords(String myField)
     // pre-logic
     return SubHelper.getRecords(myField);

class without sharing SubHelper 
   public static List<MyCustomObject> getRecord(String myField)
      return [SELECT Id, Name FROM MyCustomObject WHERE MyCustomField := myField); 

So, in order to SubHelper accessing the MyCustomObject, I had to change InvocableClass from "with sharing" to "without sharing".

Is there another way to do that?

  • 1
    Please edit to show the relevant parts of the invocable method and its class declaration. Could this be a sharing issue? (Is the class "with sharing" or inherited sharing (implicit or explicit)?)
    – Phil W
    Mar 4 at 22:40
  • @phil-w I have done that...please, take a look Mar 5 at 20:44
  • Code snippets for the relevant aspects help far more than bullet explanations. Obviously we don't want a code dump, so you do need to only include the important stuff - the class and method declarations, the lines of code that are relevant (calls from one method/class to the other and SOQL statements with basic detail; the object queried and the WHERE clause are key).
    – Phil W
    Mar 5 at 22:41
  • 1
    with sharing means sharing rules enforced so subhelper class runs and enforces record visibility rules; when you ran as admin, you have View All Data; when query was done in the VF controller, you were running without sharing hence user could see records
    – cropredy
    Mar 6 at 20:00
  • I've changed the main class to use without sharing, it worked as expected. But, how could I allow the main class and enclosing classes to access the records without changing the class permission to "without sharing"? that's my question. Mar 7 at 18:26


You must log in to answer this question.

Browse other questions tagged .