Sub topic 17
Deploying and switching over safely
This chapter covers the last step of a migration: moving tested flows into production and retiring the old automation without duplicate firing or lost behavior. It assumes you have a migrated flow tested in a sandbox, including the 200-record bulk test from the previous chapter. It also assumes you can read Salesforce DX project metadata and use Setup in production. Chapter-specific prerequisites are the same as the tutorial's: a sandbox or Developer Edition org and a working knowledge of the automations you are replacing.
Why cutover needs a plan
A Workflow Rule and the flow that replaces it do the same job. If both are active at the same time, every qualifying record gets the field update twice, the email twice, and the Task twice. If you deactivate the old one first and the flow is not yet active, records saved in the gap get no automation at all.
Time-dependent actions add a second problem. Pending actions already queued by a Workflow Rule or process belong to the old automation. A new scheduled path only applies to records that meet the flow's entry conditions after the flow is active. Records that were already waiting are not picked up.
So a safe cutover answers four questions:
- How do the flows get to production?
- In what order do you turn the new automation on and the old one off?
- What happens to work that is already queued?
- How do you go back if something is wrong?
Getting flows into production
Flows are metadata. You can move them with change sets, the Metadata API, or Salesforce CLI. Source-driven deployment is easier to review and repeat, so the examples use the CLI.
Each flow version is a .flow-meta.xml file. Its <status> element decides whether it deploys as active. By default, production receives flows as inactive unless the org setting Deploy processes and flows as active is enabled in Setup under Process Automation Settings. Treat that default as a safety feature. It lets you deploy during the day and activate in a planned window.
Validate first, then deploy using the validated result. A validation runs the same checks as a deployment but commits nothing. A quick deploy then reuses the successful validation, so the production change itself is short.
# 1. Validate against production, running local tests
sf project deploy validate \
--source-dir force-app/main/default/flows \
--test-level RunLocalTests \
--target-org prod
# 2. Later, in the cutover window, deploy the validated job
sf project deploy quick \
--job-id 0AfXXXXXXXXXXXXXXX \
--target-org prodReplace the job ID with the one printed by the validate command. A validation is eligible for quick deploy for 10 days, and it becomes invalid if the same metadata changes in the meantime. If you deploy Apex or custom fields the flow depends on, include them in the same package so the flow does not reference something missing.
Include the Apex test class from your sandbox work, such as ClosedWonFlowTest, in the deployment. Passing tests prove the flow behaves correctly against production metadata, not just sandbox metadata.
The cutover sequence
Do the work in a short, planned window, ideally when few users and integrations are saving records on the affected object.
The sequence chooses a brief overlap over a gap. Activating the flow first and deactivating the old automation immediately afterward means no save goes unhandled, at the cost of a few seconds when both could fire. If your automation is not idempotent (for example, it creates records), reverse the order and accept a brief gap instead. Choose per object and write the choice down.
Work one object at a time. The consolidation design from earlier chapters groups automation by object, so that is the natural unit of cutover. Moving one object per window keeps the blast radius small and makes a failure easy to trace.
Handling queued time-dependent work
Before you deactivate a Workflow Rule that has time-dependent actions, check what is waiting. In Setup, open Time-Based Workflow and search for the rule's pending actions. Record how many there are and when they are due.
For each group of pending actions, pick one option:
- Let them finish. If the delay is short, schedule the cutover after the last pending action fires.
- Recreate them. If the delay is long, run a one-time update or script that causes qualifying records to re-enter the flow's scheduled path. This only works if the entry conditions can be met again by a harmless change.
- Accept the loss. If the action is minor, document that in-flight reminders will not fire.
Behavior for pending items when you deactivate a rule or process version can differ, so test it in a full or partial sandbox with a queued item before you rely on it. Do not assume the sandbox and production queues match.
Verifying after activation
Run a smoke test immediately, using real but low-risk records. For the Closed Won example, move one test Opportunity to Closed Won and check three things:
- Exactly one follow-up Task exists.
- The field updates match what the old rule produced.
- No fault emails or errors appear.
Then check the monitoring tools:
- Paused and Failed Flow Interviews in Setup shows failures from after-save flows.
- Flow fault emails go to the person who last modified the flow, so confirm that address belongs to someone who will read it, or add fault paths that notify a shared queue.
- Debug logs for a test user show the flow interview and each element.
Also test the entry points that bypass the user interface. Data Loader jobs, integrations, and Apex DML all trigger record-triggered flows. A flow that works for one UI save can still fail on a bulk load if it hits limits.
Rollback and cleanup
Keep the old automation inactive, not deleted, during a soak period. A week or a full business cycle works for many orgs, so month-end processing is covered if it matters. Rolling back is then a matter of deactivating the flow and reactivating the Workflow Rule or process. Flow versions help too: if only a recent edit is wrong, activate the previous version of the flow.
Once the soak ends with no defects, remove the old automation in a separate deployment. A destructive changes file deletes the rules:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Opportunity.Closed_Won_Task</members>
<name>WorkflowRule</name>
</types>
<version>60.0</version>
</Package>Save this as destructiveChanges.xml next to an empty package.xml. Workflow Rules must be inactive before they can be deleted, and the actions they referenced (field updates, email alerts) remain until you remove them as well. Deleting everything in one pass is optional. Leaving unused actions behind is clutter, not risk, but removing them keeps the next audit clean.
Common errors
| Symptom | Likely cause |
|---|---|
| Duplicate Tasks or emails | The old rule or process is still active, or two flows share overlapping entry conditions |
| Nothing fires after deploy | The flow arrived inactive and was never activated |
| Reminders never sent for old records | Pending time-dependent actions were not recreated for the new scheduled path |
| Deploy fails on a dependency | A field, Apex class, or email template used by the flow is missing from the package |
| Failures only during data loads | The flow is not bulk-safe or hits a limit that single saves do not |
Exercise
Your flow deploys to production inactive. A Workflow Rule on the same object creates a Task and has a time-dependent email action with 300 pending actions in the Time-Based Workflow queue. Describe the order of steps you would use to cut over, and what you would decide about the 300 pending actions.
Show answer
Deploy the flow inactive using a validated quick deploy. Check the Time-Based Workflow queue and note the 300 pending actions and their due dates. Decide for them: wait until they fire if the delay is short, recreate them by making records re-enter the scheduled path if the delay is long, or document that they will be lost. In the window, activate the flow, then deactivate the Workflow Rule right away to avoid a gap (use the reverse order if the Task creation cannot tolerate a brief double fire). Smoke test one record for exactly one Task, monitor failed interviews, keep the old rule inactive for a soak period, and delete it in a later deployment.