The release passed every check. Every flow in it was switched off.
A sales release validated 29 of 29 tests and deployed Succeeded, and the first real lead converted wrong four different ways. All 13 flows had landed in production as Draft, because production deploys flows inactive unless "Deploy processes and flows as active" is on. Why the validation could not notice, how a FlowDefinition Tooling API query found it, the prod-safe smoke test that now fails when flows are not active, and the record type picklist default that was a separate bug hiding in the same symptoms.
The sales release went to production on a Monday. The validation passed. The deploy said Succeeded. That evening the client entered the first real builder lead and converted it.
The Opportunity came out on the wrong sales path, with only two stages to choose from. It was named after the builder’s company with a dash hanging off the end. It had no property. The builder’s account had the job site as its billing address. And the lead itself had been routed to the service dispatcher instead of sales.
Four symptoms that looked like four bugs. They were one setting.
What the first lead actually showed
At Doorvana, a builder lead converts through standard lead conversion, and then an
after-save record-triggered flow on Lead, Lead_Convert_Build_Property_And_Household, does the
rest: it sets the Opportunity record type from the lead’s Line of Business, builds the job site
Location, and overwrites the Account billing address from the lead’s billing fields. A before-save
flow on Opportunity, Opportunity_Set_Name, names the job from its property. Two before-save flows on
Lead stamp the company name and the assignment path.
Read against that list, the symptoms were exactly what standard lead conversion does on its own:
- The Opportunity got the converting user’s default record type, Service, whose sales process is the short transactional one: Quoted, Closed. An Installation Opportunity runs the bid process and should have opened at Discovery.
- The name was the convert dialog’s default, the Company followed by a dash. That default has fooled me before, when the cause turned out to be the lead’s data. This time it was not the data.
- With no flow to build one, there was no property.
- Lead conversion copies the Lead address into Account billing. For a builder lead, the Lead address is the job site, which is why the flow exists to put it back.
None of the project’s own automation had run.
Thirteen flows, none of them on
A Tooling API query on FlowDefinition settled it. Of the 13 flows in the sales release, 11 had a
null ActiveVersionId. They had been deployed and had never been switched on. The other two,
Service_Lead_Stamp_Assignment_Path and Service_Lead_Stamp_Company, did have active versions:
the ones from June. One was active on version 2 against a latest of 3, the other on 1 against 2.
In the sandbox, all 13 ran their latest version.
That explains the routing too. The June version of the assignment-path flow predates the rule that sends a request for pricing (Request Type RFP) to sales, so the lead went to Tech Dispatch.
The cause is a production default. Production deploys flows inactive unless Process Automation Settings → “Deploy processes and flows as active” is turned on. In this org it is off. A new flow arrives as Draft with no active version; an updated flow arrives as a new Draft version while the old one keeps running. The deploy result reports Succeeded and says nothing about it.
Why the validation could not see it
This is the part worth slowing down on, because the release was not careless. The check-only
validation that approved it ran RunLocalTests against production and passed 29 of 29.
The tests that exercise these flows live in SalesReworkTest and PropertyAndBillingTest: 48 of
them. They build their data through a Field Service TestDataFactory that is not part of the sales
release, so they could not go to production with it, and they were left out. That left 29 tests,
and not one of them asserted anything a flow does. They passed with the flows off exactly as they
would have passed with them on.
Either failure alone would have been caught by the other. Flows deploying inactive is caught by a test that needs them. A test selection with no flow tests is harmless if the flows deploy active. Together they produced a green validation, a successful deploy and a broken first record.
The same release had already been bitten once by its test selection that morning. The first
production validation failed with Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required for AccountTrigger, although a passing test inserted an Account. The insert
used Database.insert(account, options) with Database.DMLOptions, which allows partial success
unless OptAllOrNone is set, so it failed quietly on a required field and the test carried on. In
the sandbox, other test classes covered the trigger; those classes were not in the release. (That
overload has its own post.) The lesson was the same both
times: a release’s tests have to stand on their own in the target org.
A smoke test production can run
The fix for the release process is SalesReleaseSmokeTest. It touches only objects that exist in
production, uses only invented records, and goes into every sales release. It converts a builder
bid lead and asserts what the flows are supposed to produce:
force-app/main/default/classes/SalesReleaseSmokeTest.cls
@IsTest
static void shouldConvertBuilderBid_ToInstallationWithPropertyNameAndBilling() {
Lead lead = builderBidLead();
Database.insert(lead, allowDuplicates());
Database.LeadConvert conversion = new Database.LeadConvert();
conversion.setLeadId(lead.Id);
conversion.setConvertedStatus(CONVERTED_STATUS);
Database.LeadConvertResult result = Database.convertLead(conversion, allowDuplicates());
Assert.isTrue(result.isSuccess(), 'Conversion should succeed: ' + result.getErrors());
Opportunity opportunity = [
SELECT Name, RecordType.DeveloperName, StageName, Location__c, Location__r.Site_Street__c
FROM Opportunity WHERE Id = :result.getOpportunityId()
];
Assert.areEqual('Installation', opportunity.RecordType.DeveloperName,
'Lead_Convert_Build_Property_And_Household sets the record type from Line of Business');
Assert.areEqual('Discovery', opportunity.StageName, 'Installation runs the Bid sales process');
Assert.isNotNull(opportunity.Location__c, 'A confirmed builder job site becomes a property');
Assert.isFalse(opportunity.Name.endsWith('-'), 'Not the convert dialog default, got: ' + opportunity.Name);
Account account = [SELECT BillingStreet, BillingCity FROM Account WHERE Id = :result.getAccountId()];
Assert.areEqual('9 Head Office Rd', account.BillingStreet, 'A business is billed at the Billing Address it gave');
} Its allowDuplicates() helper sets OptAllOrNone = true alongside the duplicate-rule header, so a
failed insert throws instead of passing quietly. A second test inserts an RFP lead and a service
call and asserts that the first gets the sales assignment path and the second gets Tech Dispatch.
The proof that it works was to run it before fixing anything. A check-only
sf project deploy validate against production with RunLocalTests failed exactly the way the
client’s lead had:
Lead_Convert_Build_Property_And_Household sets the record type from Line of Business: Expected: Installation, Actual: null
RFP goes to sales (labelled SDR): Expected: Inside Sales, Actual: Tech Dispatch
A test that reproduces the production bug before the fix is the only kind I trust to catch it next time.
Switching them on, and checking every time
Activation went through the Tooling API, which is the same change as clicking Activate on a version in Setup. A script reads the flow list from the release manifest, reports every flow whose active version is not its latest, and activates only when asked:
scripts/activate-flows.py (excerpt)
result = sf('data', 'query', '--use-tooling-api', '--target-org', org, '--query',
'SELECT Id, DeveloperName, ActiveVersion.VersionNumber, LatestVersion.VersionNumber '
f'FROM FlowDefinition WHERE DeveloperName IN ({quoted})')
# ...
for flow_id, name, latest in stale:
body = json.dumps({'Metadata': {'activeVersionNumber': latest}})
res = sf('api', 'request', 'rest', f'/services/data/v66.0/tooling/sobjects/FlowDefinition/{flow_id}',
'--method', 'PATCH', '--body', body, '--target-org', org) All 13 flows were activated, the assignment-path flow on version 3 and the company stamp on version
2. The validation of the fix then passed: 6 of 6 components, 32 of 32 tests. And the fix itself
showed the trap again straight away: it contained an updated New_Service_Lead screen flow, and after
the quick deploy that new version was Draft too, until the script activated it.
It shows up from the other direction as well. A later change added a brand-new flow together with a test for it. The production validation deploys that flow as Draft and runs its test against nothing, so the test fails even though the flow is right. With the setting off there are two ways through: deploy the flow on its own and activate it before the test ships, or turn “Deploy processes and flows as active” on. Turning it on is still an open decision for this org; the smoke test is what makes it a reasonable one.
The symptom that had its own cause
One thing on that first lead was not the flows. The builder’s lead had Lead Role = Homeowner, and nobody had picked it.
The Service_Lead record type carried its own default for Lead_Role__c, separate from the
field’s value set:
force-app/main/default/objects/Lead/recordTypes/Service_Lead.recordType-meta.xml (diff)
<values>
<fullName>Homeowner</fullName>
- <default>true</default>
+ <default>false</default>
</values> The intake screen flow never set the field at all, so every lead of that record type started as a homeowner. The default is gone, and the screen now asks for a required Lead Role and a Title when the Client Type is a business; homeowner leads are still stamped Homeowner by formula. The smoke test covers this one too, by loading the record type’s defaults the way a user’s new record would:
force-app/main/default/classes/SalesReleaseSmokeTest.cls
Id serviceLead = Schema.SObjectType.Lead.getRecordTypeInfosByDeveloperName().get('Service_Lead').getRecordTypeId();
// newSObject(..., true) loads the record type's picklist defaults, the same ones a user sees on a new record.
Lead lead = (Lead) Lead.SObjectType.newSObject(serviceLead, true);
Assert.isNull(lead.Lead_Role__c, 'A Builder lead must not start out as Homeowner'); What it comes down to
The automation was not wrong. The source was right, the sandbox was right, 52 sandbox tests passed. Everything that failed was in how the release reached production. The first real lead was the test the release did not have.
Practical summary
- Production deploys flows inactive unless Process Automation Settings → “Deploy processes and flows as active” is on. New flows arrive with no active version; updated flows keep their old active version. The deploy still says Succeeded.
- Query
FlowDefinitionwith the Tooling API after every production deploy that contains a flow, and compareActiveVersion.VersionNumberwithLatestVersion.VersionNumber. - Activate with a Tooling API
PATCHonFlowDefinitionsettingMetadata.activeVersionNumber. RunLocalTestspassing proves nothing about tests that were left out of the release. Ship a prod-safe smoke test that asserts what the flows produce, and run it before the fix to see it fail.- A validation that adds a flow and its test together runs the test against a Draft flow.
- When a field fills itself in, check the record type’s
picklistValuesfor a<default>true</default>, and test it withnewSObject(recordTypeId, true).