This script helps with disabling and enabling automation (Triggers, Flows, Process Builders, Workflow Rules, Duplicate Rules and Validation Rules) in a Salesforce org, especially useful for data migrations.
- Make sure the Salesforce CLI is installed
- Optional(recommended) - use a Python Virtual Environment i.e.
venv
,conda
orvirtualenv
- If you are using
venv
, then locate thevenv
folder and activate i.e. run this in the terminal:source venv/bin/activate
- If you are using
- Make sure the packages are installed in your local machine by running :
pip install -r requirements.txt
- Setup
.env
file at the root level-
SFUSERNAME
- username for logging into the Salesforce Org -
SFPASSWORD
- password for your SFUSERNAME -
SECURITY_TOKEN
- usually provided when you change your password. Or get a new one from Personal Settings > Reset My Security Token -
SFORGALIAS
- sfdx alias for your Salesforce Org in your local machine- Can use the following command to set it up:
sfdx auth:web:login -a TestOrg1 -r https://MyDomainName--SandboxName.sandbox.my.salesforce.com
, whereTestOrg1
is your SFORGALIAS.
- Can use the following command to set it up:
-
Example:
SFUSERNAME=user@email.com.dev SFPASSWORD=00000000000 SECURITY_TOKEN=0000000000000000000000000 SFORGALIAS=TestOrg1 SALESFORCE_API_VERSION=55.0
-
Main.py
is the driver for all the logic.
In it, the disable_automation
and enable_automation
booleans are used to trigger different sets of logics. If disable_automation
is set to true, it will attempt to disable Triggers, Validation Rules, Duplicate Rules, Flows, Process Builders and Workflow Rules. It also saves the original states of the metadata in JSON files.
Similarly, toggling enable_automation
to True
will return the org to its original state. Nothing happens if both are set to False
.
To run script, on the command line run: python src/main.py
- Setup an org project
- Fetch Triggers Metadata from Org using the metadata api
- Save the original state to a JSON file (OriginalTriggerState.json)
- Change the Triggers state from 'Active' to 'Inactive'
- Fetch Duplicate Rules Metadata from Org using the metadata api
- Save the original state to a JSON file (OriginalDuplicateRuleState.json)
- Change the Duplicate Rule state from 'Active' to 'Inactive'
- Generate a package.xml for deploying Triggers and Duplicate Rules
- Fetch FlowDefinitions Metadata from Org using the tooling api
- Save the original state to a JSON file (OriginalFlowState.json)
- Fetch Validation Rules Metadata from Org using the tooling api
- Save the original state to a JSON file (OriginalValidationRuleState.json)
- Fetch Workflow Rules Metadata from Org using the tooling api
- Save the original state to a JSON file (OriginalWorkflowRuleState.json)
- Create payloads for turning off FlowDefinitons, Validation Rules and Workflow Rules
- Deploy Triggers via the metadata api, and FlowDefinitons, Validation Rules and Workflow Rules via the tooling api
- Reverse the changes using the original state using the json files generated in the deactivation process.
- Clean-up project (delete "/output" folder)