This is a known dependency sequencing issue with SFDX and Change Sets. The error occurs because Change Sets process components alphabetically by type, not by dependency order. Your Flow references fields that aren’t yet committed when the Flow validation runs.
Here’s the complete solution addressing all three focus areas:
Flow and Custom Object Dependencies:
The core issue is that Flows validate their field references during deployment, but Change Sets don’t guarantee the custom object is fully committed first. You need to ensure Contract_Extension__c and ALL its fields (including Approval_Status__c) exist before the Flow deploys.
SFDX Project Structure Fix:
Restructure your deployment using package.xml with explicit ordering:
<Package>
<types><members>Contract_Extension__c</members><name>CustomObject</name></types>
<types><members>Contract_Approval_Flow</members><name>Flow</name></types>
<version>59.0</version>
</Package>
Deploy using: `sfdx force:source:deploy -x package.xml --testlevel NoTestRun
Change Set Component Inclusion Best Practice:
Abandon Change Sets for this use case. They’re not designed for complex metadata dependencies. Instead, implement a two-phase SFDX deployment:
Phase 1 - Deploy foundation:
sfdx force:source:deploy -m "CustomObject:Contract_Extension__c" -u production
Phase 2 - Deploy Flow after validation:
sfdx force:source:deploy -m "Flow:Contract_Approval_Flow" -u production
Alternatively, use Unlocked Packages which handle dependencies automatically. Create a package with both components:
sfdx force:package:create --name ContractAutomation --packagetype Unlocked
sfdx force:package:version:create --package ContractAutomation --wait 10
Unlocked packages analyze dependencies and deploy in correct order automatically. This is the most reliable approach for contract automation rollouts.
Additional Verification:
Before deploying, validate your Flow’s field references match exactly:
- Open Contract_Approval_Flow.flow-meta.xml
- Search for all Contract_Extension__c field references
- Cross-check against Contract_Extension__c/fields/ directory
- Ensure API names match exactly (case-sensitive)
If you must use Change Sets temporarily, deploy in three separate Change Sets with 30-minute gaps: (1) Custom Object only, (2) Custom Fields only, (3) Flow only. This forces proper sequencing but is inefficient compared to SFDX CLI or packages.