Wednesday, December 14, 2022

How To Stop Workflow Rules and Outbound Messages in Sandbox Automatically

We have couple of outbound messages linked under the workflow rules and all these outbound message will send some of custom objects data and standard objects data to external systems everytime any kind of DML operation happens on these objects. 

Everything got set up and working as expected. But recently we have come across a situation where all the outbound messages are pushing data from sandboxes to same external systems assuming that we forgot to disable these workflow rules in sandbox before we activate it and somehow we missed to change the outbound messages end point from production to sandbox.

Because of all these things the sandbox data got messed up with the production data. So, we started exploring the options how can we stop all these Workflow rules automatically in sandbox or can we change the endpoint from production to stage automatically after refreshing the sandbox.

As a solution we come across multiple options but as a quick fix we have chosen to use the below solution.


1. Identify the environment like sandbox or production.

  • Use the username to identify this assuming we will add sandbox name in the end of username but in production we will not have any name after email Id.
  • Use the SOQL to identify the environment 
2. Assuming we have decided to move with username flow create a formula field on User Object as Checkbox. 

3. Assume formula field name as "isProduction__c" and this will get updated to true in case of if user in production env and else false in sandbox.

4. Use this field in all your workflow rule by adding CurrentUser under that select isProduction__c field.

Now all your workflow rules will get evaluated to true if the logged in user in production else the rule will not get satisfied so your Workflow rules will not get fired in sandbox. 

With this approach we don't need to worry about the disabling the workflow rules and changing the outbound messages endpoints to stage. We can use other options to as well but we thought this is simple and easy to implement for Admins too...

Happy Learning 😊 

No comments:

Post a Comment