[SalesForce] Auto Launched flow running in User mode

We have an auto launched flow which whenever a work order is rejected by a tech, it auto-dispatches work order to another available tech. We're calling the auto launched flow through a process builder which is trigger by a field update when the WO is rejected.

The auto dispatch is working great if the WO is rejected by an internal CSR on behalf of the service provider but when the service provider rejects, it is not auto dispatching. It feels like the auto launched flow is respecting the permissions and access of the service provider instead of running in system mode. I tried multiple ways but with no success. How do I make sure to run it in system mode but not in user mode?

Here's how the process works: Service Provider Rejects a WO by clicking on Reject button in the community which calls an on screen flow where he specifies the reason for his rejection. I have an invocable apex action at end of the flow which updates the field, which triggers the process builder which then calls an auto launched which dispatches the work order. Everything works well If user is a CSR but not when the user is a Service Provider. I'm using without sharing keyword as well.

Best Answer

Because you are using flow, it will respect user permissions. If you were to invoke a visual flow instead and use invokable APEX you could get around this and run in system mode using the without sharing keyword on the class.

But what I think is the best approach in this use case would be to use a visual flow and use a session based permission set that gets activated only for the step where the auto dispatch is supposed to fire. I prefer this approach because it further clarifies the intention of those implementing this solution --> the without sharing notation on the apex class could be there for many reasons and without any explanation.

Related Topic