The form stopped asking. Every old version of it still did.
The client changed two intake decisions overnight: one Builder Homeowner lead source instead of two values, and no door counts on the Lead. Retiring a LeadSource value through a StandardValueSet deploy, the test that would have passed against a retired value, and the field delete that failed because flow versions that can never run again still held references to it.
The client changed their mind overnight about two questions on the intake form.
The first was where a lead came from. A homeowner sent by one of the builders the company works with had been two separate choices the day before; now it was one. The second was door counts. The form had been asking how many single, double and oversized doors the house had, and the honest answer at that moment is nobody knows. That number comes from the quote.
Taking the questions off the screen took minutes. Taking the fields behind them out of the org ran into every version of the form that had ever existed.
One lead source, not two
At Doorvana the previous day’s decision had added two values to the standard
LeadSource picklist, Builder and Homeowner. The correction was a single value,
Builder Homeowner, which means exactly the case the business cares about: a homeowner whose
builder sent them.
LeadSource is a standard picklist, so its values live in a StandardValueSet, and the record
type has to enable each value separately. Both changed in source:
force-app/main/default/standardValueSets/LeadSource.standardValueSet-meta.xml (diff)
<standardValue>
- <fullName>Builder</fullName>
+ <fullName>Builder Homeowner</fullName>
<default>false</default>
- <label>Builder</label>
+ <label>Builder Homeowner</label>
</standardValue>
...
- <standardValue>
- <fullName>Homeowner</fullName>
- <default>false</default>
- <label>Homeowner</label>
- </standardValue> Deploying the value set without the old values did not delete them. It left them inactive. A describe no longer lists them as active values, and any record that already carried one keeps it, which is what you want: history is not rewritten by a picklist change.
Everything that tested for the old values had to move to the new one. The formula field
Is_Referral_Lead__c drives layout logic and reporting:
force-app/main/default/objects/Lead/fields/Is_Referral_Lead__c.field-meta.xml (diff)
- <formula>OR(BEGINS(TEXT(LeadSource), "Referral -"), ISPICKVAL(LeadSource, "Builder"), ISPICKVAL(LeadSource, "Homeowner"))</formula>
+ <formula>OR(BEGINS(TEXT(LeadSource), "Referral -"), ISPICKVAL(LeadSource, "Builder Homeowner"))</formula> The intake screen flow, New_Service_Lead, has its own formula, Source_Needs_Referrer, that
decides whether to ask which builder sent the lead. It now keys on Builder Homeowner alone.
The previous version also checked that the Client Type was Homeowner; the new value means
homeowner by definition, so that condition went. (The flow and its override have
their own post, and the referral rule’s earlier
history is in the rename post.)
The test that would have passed anyway
The obvious test for “the old values are retired” is to insert a Lead with one and expect a
failure. It would not fail. LeadSource is not a restricted picklist, so an insert with an
inactive value saves without complaint, and a test built that way passes whether or not the
value was ever retired.
The test reads the active entries instead:
force-app/main/default/classes/SalesReworkTest.cls
@IsTest
static void shouldOfferOneBuilderHomeownerSource() {
Set<String> active = new Set<String>();
for (Schema.PicklistEntry entry : Lead.LeadSource.getDescribe().getPicklistValues()) {
if (entry.isActive()) {
active.add(entry.getValue());
}
}
Assert.isTrue(active.contains('Builder Homeowner'), 'Builder Homeowner should be active');
for (String retired : new List<String>{ 'Builder', 'Homeowner', 'Referral - Builder' }) {
Assert.isFalse(active.contains(retired), retired + ' should not be an active Lead Source');
}
} Door counts off the Lead
The second correction was to remove Single_Door_Count__c, Double_Door_Count__c and
Oversized_Door_Count__c from the Lead entirely. The Opportunity keeps its own door count
fields; that is where the number becomes known.
A field on a Lead that gets converted is referenced from more places than the form. Taking it out meant editing every one of them:
- the
New_Service_Leadscreen flow; - both Lead Lightning record pages;
- the Lead page layout;
- the lead conversion field mapping, in
LeadConvertSettings; - the
Doorvana_Basepermission set, and field permissions on the profiles and other permission sets that had them.
The conversion mapping is the one that is easy to forget, because nothing on screen shows it:
force-app/main/default/LeadConvertSettings/LeadConvertSettings.LeadConvertSetting-meta.xml (diff)
- <mappingFields>
- <inputField>Single_Door_Count__c</inputField>
- <outputField>Single_Door_Count__c</outputField>
- </mappingFields>
...
- <mappingFields>
- <inputField>Oversized_Door_Count__c</inputField>
- <outputField>Oversized_Door_Count__c</outputField>
- </mappingFields> That deployed, and all 67 Apex tests passed. Then came the part that should have been one line.
The delete that would not validate
With nothing active using them, the three field files came out of source and the deletion went to a validation run. It failed:
This custom field is referenced elsewhere in salesforce.com. : Flow Version - 301…
(The ID after Flow Version - is trimmed here.) The active version of New_Service_Lead no
longer touched the door counts. Obsolete versions of the same flow did.
Every time a flow is saved as a new version, the old one stays in the org. An obsolete version can never run again: it is not active, and nothing can call it. It still holds a hard reference to every field it used, and that reference blocks a field delete exactly as an active one would.
Old flow versions can be deleted through the Metadata API. Each one is a Flow member whose
name carries the version number after a hyphen. The destructive deploy listed versions 1
through 7, in this shape:
destructive changes manifest (shape)
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>New_Service_Lead-1</members>
<members>New_Service_Lead-2</members>
<!-- … through … -->
<members>New_Service_Lead-7</members>
<name>Flow</name>
</types>
<version>67.0</version>
</Package> That deployed. The field deletion went back to validation, and failed again, this time naming versions 15 and 16. They had been blocking it all along. The first error message was truncated, and it showed only part of the list.
Versions 15 and 16 were deleted the same way. The next validation of the field deletion passed with 67 of 67 tests, and the deploy went through.
What did not get deleted
Two things were left alone on purpose.
In the sandbox, the deleted fields were left in the deleted-fields list and not purged.
In production, the three Lead door count fields already exist and already hold values on real Leads. The release takes them off every page and out of the intake, and does not delete them. Removing a field with data in it is a separate decision from removing a question from a form, and nobody had made the first one.
The same goes for the retired lead source values. Production still has an older referral value
active on a small number of records. At release, those records move to Builder Homeowner
before the old value goes inactive, so nothing ends up carrying a value users can no longer
pick.
Practical summary
- Removing a value from a
StandardValueSetin source and deploying it leaves the value inactive, not deleted. Records keep it. LeadSourceis not restricted. A test that inserts a retired value passes anyway; assert ongetPicklistValues()entries whereisActive()is true.- Removing a converted Lead field touches the screen flow, the Lightning record pages, the page layout, the lead conversion field mapping and field permissions. The mapping is the one with no visible symptom.
This custom field is referenced elsewhere in salesforce.com. : Flow Version - …can name an obsolete version. Inactive versions keep their references.- Delete old versions with a destructive deploy listing
Flowmembers asFlowName-N, and validate again after each round: the first error did not list every blocking version. - Taking a question off a form and deleting the data behind it are two decisions. Make the second one on its own.