You can't name a job after an address it hasn't been told yet

Converted Opportunities were supposed to read as the street and the line of business. Lead conversion creates the Opportunity before the property exists, so a before-save flow on create never sees it. How the naming moved to the update that follows, how repeat jobs keep their numbers through a rename, what standard conversion does to the Account billing address, the one-word picklist default that would have turned every builder's office into a job site, and why a name ending in a dash turned out to be the data, not the flow.

A receptionist takes a call about a house that does not have an address yet. It is a lot in a new subdivision. She types “Smith Residence” and a lot number, the job gets a property and a sensible name, and when the street address arrives weeks later, one action renames the property and every job hanging off it. The builder who sent the job keeps getting invoiced at his office.

None of that worked a day earlier. The convert dialog offered names like a business name followed by a dash, and the address on a lead meant two different things depending on who had called.

Both problems came down to timing: what exists, and when, during Salesforce lead conversion.

The rule the client asked for

At Doorvana an Opportunity should read as the property and the line of business, with a number for repeat work at the same place:

  • Every job with a property: Property Name – Line of Business
  • Manufacturing & Supply, which ships to a dealer and has no job site: Supply – Account – date
  • A job with no property yet: Line of Business – Property TBD

The first version of this rule put the builder’s Account name in front of wholesale jobs. Two days in, the client dropped the Account from every title except Supply, so a builder’s job reads exactly like a homeowner’s.

The Line of Business is the Opportunity record type. The property is a standard Field Service Location, linked from the Opportunity by Location__c. Location.Name is the street address, or the name the receptionist typed while the address is still TBD.

Easy, with a before-save flow on Opportunity create. Except it can’t work on create.

The Opportunity exists before the property does

Standard lead conversion only ever creates an Account, a Contact and an Opportunity. It has no mapping path to Location. In this org the property is built afterwards, by an after-save flow on Lead, Lead_Convert_Build_Property_And_Household, which runs when IsConverted becomes true. It creates or matches the Location, links it to the Account with a standard AssociatedLocation, and stamps Opportunity.Location__c. (The household side of that flow is its own post.)

So at the moment the Opportunity is inserted, there is no address to name it after. A before-save flow on create alone would never see the property.

The name can only be built on the update that stamps Location__c. A later rename of the Location reaches the same flow through a stamp field.

Opportunity_Set_Name is a before-save flow on create and update. The start element’s filter lets it run on insert and then again whenever something the name depends on changes:

force-app/main/default/flows/Opportunity_Set_Name.flow-meta.xml

<start>
    <filterFormula>OR(ISNEW(), ISCHANGED({!$Record.Location__c}),
      ISCHANGED({!$Record.RecordTypeId}), ISCHANGED({!$Record.Property_Name_Stamp__c}))</filterFormula>
    <object>Opportunity</object>
    <recordTriggerType>CreateAndUpdate</recordTriggerType>
    <triggerType>RecordBeforeSave</triggerType>
</start>

On the insert from conversion, an Opportunity outside Manufacturing & Supply has no property, so the flow gives it a placeholder, Installation – Property TBD, and clears Property_Sequence__c so a later property starts a clean count. When the Lead flow stamps Location__c, that update is the one that gives it its real name. An Apex test pins the sequence down end to end, converting a fabricated homeowner lead and reading the name back:

force-app/main/default/classes/SalesReworkTest.cls

@IsTest
static void shouldNameConvertedOpportunity_FromStampedLocation() {
    Lead converted = convert(newLead('Homeowner', 'Service', 'Owner - Occupied'));
    Opportunity opportunity = new Opportunity(Id = converted.ConvertedOpportunityId);
    Assert.areEqual('1847 Cedar Ridge Dr – Service', nameOf(opportunity),
        'Renamed when conversion stamps the Location');
}

A side effect worth stating: a name someone edits by hand stands until the Location, the record type or the property name changes. Then the rule takes over again.

Numbering repeat work without renumbering it

The second service call to the same house should read 1847 Cedar Ridge Dr – Service – 2. The flow counts other Opportunities at the same Location__c with the same record type, excluding the record itself (which already exists when the stamp arrives after conversion), and uses AssignCount on the result. AssignCount on an empty collection gives 0, so the first job gets no suffix.

Then the rename case broke it. When a TBD lot gets its real street address, every Opportunity at that property has to be renamed. Recounting at that moment gives each of them the same count, and so the same suffix. The number has to be kept, not recalculated, so it now lives in Property_Sequence__c:

force-app/main/default/flows/Opportunity_Set_Name.flow-meta.xml

<formulas>
    <description>A rename keeps each Opportunity its number. Recounting would give every
      Opportunity at the property the same suffix.</description>
    <name>Keep_Sequence</name>
    <dataType>Boolean</dataType>
    <expression>AND(NOT(ISBLANK({!$Record.Id})),
  {!$Record.Location__c} = {!$Record__Prior.Location__c},
  {!$Record.RecordTypeId} = {!$Record__Prior.RecordTypeId},
  NOT(ISBLANK({!$Record.Property_Sequence__c})))</expression>
</formulas>
<formulas>
    <name>New_Sequence</name>
    <dataType>Number</dataType>
    <expression>IF({!Keep_Sequence}, {!$Record.Property_Sequence__c}, {!Other_Opportunity_Count} + 1)</expression>
</formulas>

Opportunity.Name is capped at 120 characters, so the base name is cut before the suffix and the number always survives.

The rename itself is a record-triggered flow on Location, Location_Rename_Opportunities, filtered to ISCHANGED({!$Record.Name}). It does not build any names. It writes the new property name into Property_Name_Stamp__c on each Opportunity, and that change is what re-runs Opportunity_Set_Name. One flow owns the naming rule; the other only pokes it.

One address field doing two jobs

The harder problem was the address itself. On a homeowner lead, the Lead address is the house. On a builder prospect, it is the builder’s office. An earlier fix kept builder prospects from creating a property at their office. This round added business clients calling about a real job site, which meant the same field could now be either thing for the same Client Type.

Before deciding anything, a rolled-back Apex probe checked what standard conversion does with the Lead address on the Account:

  • a new Account gets the Lead address as its billing address;
  • an existing Account with blank billing gets it too;
  • an existing Account with billing already populated is left alone.

For a business client calling about a job site, that copy puts the job site in billing, which is not where the client is invoiced. So the conversion flow now corrects billing, but only while billing still matches the Lead address, meaning conversion copied it or it was blank:

force-app/main/default/flows/Lead_Convert_Build_Property_And_Household.flow-meta.xml

<formulas>
    <description>True only when Account billing still matches the Lead address, meaning
      conversion copied it or it was blank. Anything else is a real billing address and is
      never overwritten. ... Known limit: an existing business Account whose real billing
      address is exactly this job site looks copied.</description>
    <name>Billing_Was_Copied_From_Job_Site</name>
    <dataType>Boolean</dataType>
    <expression>AND(
 TEXT({!$Record.Customer_Type__c}) &lt;&gt; "Homeowner",
 OR(NOT(ISBLANK(TEXT({!$Record.Address_Status__c}))), NOT(ISBLANK({!$Record.Billing_Street__c}))),
 BLANKVALUE({!Get_Converted_Account.BillingStreet}, "") = BLANKVALUE({!$Record.Street}, ""),
 BLANKVALUE({!Get_Converted_Account.BillingCity}, "") = BLANKVALUE({!$Record.City}, ""),
 BLANKVALUE({!Get_Converted_Account.BillingPostalCode}, "") = BLANKVALUE({!$Record.PostalCode}, "")
)</expression>
</formulas>

The thing that tells conversion the address is a job site is a new restricted picklist, Lead.Address_Status__c, on a GlobalValueSet with two values: Confirmed and TBD. Only the New Lead screen flow sets it. Blank is the signal: a Lead with no Address Status is a prospect whose address is an office, and it creates no property and keeps that address as billing.

force-app/main/default/objects/Lead/fields/Address_Status__c.field-meta.xml

<description>Set by the New Lead flow. A value here also says the Lead address is a job site.
  Blank on prospecting leads, whose address is a business office, so conversion treats the two
  differently.</description>
<type>Picklist</type>
<valueSet>
    <restricted>true</restricted>
    <valueSetName>Address_Status</valueSetName>
</valueSet>

The default that made blank impossible

The first validation run failed two SalesReworkTest methods. One read:

Nullable object asserted with non null value: A builder address is an office

The other was the same for a general contractor. Both tests create a builder-type Lead outside the intake flow, convert it, and assert the Opportunity has no Location__c. Both got one.

The cause was a single attribute. The new value set had shipped with Confirmed as its default. Every Lead created by any route other than the screen flow, through the API, an import, or a test, came out with Address Status Confirmed. To the conversion flow, that meant this address is a job site. Every builder prospect would have converted with a property at the builder’s office, linked to the builder’s Account and stamped onto the bid.

The fix was to make blank possible again. The default came off the GlobalValueSet and off the record type’s picklistValues, and the screen flow sets its own default on its own picklist:

force-app/main/default/globalValueSets/Address_Status.globalValueSet-meta.xml

<GlobalValueSet xmlns="http://soap.sforce.com/2006/04/metadata">
    <masterLabel>Address Status</masterLabel>
    <sorted>false</sorted>
    <customValue><fullName>Confirmed</fullName><default>false</default><label>Confirmed</label></customValue>
    <customValue><fullName>TBD</fullName><default>false</default><label>TBD</label></customValue>
</GlobalValueSet>

Nothing in the screen flow would ever have shown this. The flow always sets the field. The bug lived entirely in the records that do not come through it, which is why the tests that create Leads directly were the ones that caught it.

Tests rewritten, not bent

The same session changed a routing rule. A builder’s service call, or one for an unfinished property, used to go to inside sales; now Request Type decides, so a request for service goes to dispatch and a request for a proposal goes to inside sales. Existing routing tests had the old rule baked in. They were rewritten to the new rule. The alternative, quietly shaping the rule so the old assertions kept passing, is how a suite ends up protecting a decision nobody holds any more.

The dash that came back

Two days after this shipped to the sandbox, the client converted a builder’s lead and got an Opportunity called Ratliff Custom Homes-: the company name and a dangling dash. That is the default name the lead conversion dialog fills in, and it is what an Opportunity keeps whenever no automation renames it.

The obvious suspect was the ordering problem this post started with. The handoff note from the previous session had already called it an insert-order bug and proposed rebuilding the naming trigger. That rebuild would have changed nothing. Opportunity_Set_Name already re-fires on ISCHANGED(Location__c), and its Apex test proves the converted Opportunity is renamed when the stamp lands.

Querying the converted Leads found the real cause. Both failing Leads had been created before the new intake screen flow existed, so their Address_Status__c was blank. Blank is the signal described above: the conversion flow read each of them as a prospect whose address is an office, created no Location, stamped no Location__c, and the naming flow had nothing to fire on. The flow was right. The rule was right. Legacy data could not satisfy it.

The prospect rule stayed. What changed is that a missing property is now a state with a name, not a gap. Any Opportunity outside Manufacturing & Supply with no Location__c gets a placeholder built from its record type:

force-app/main/default/flows/Opportunity_Set_Name.flow-meta.xml

<formulas>
    <name>Placeholder_Opportunity_Name</name>
    <dataType>String</dataType>
    <expression>{!Get_Record_Type.Name} &amp; &quot; – Property TBD&quot;</expression>
</formulas>

The same branch clears Property_Sequence__c and the name stamp, so when a property is added later the ISCHANGED(Location__c) update numbers it from scratch. Installation – Property TBD reads as unfinished on purpose. Ratliff Custom Homes- read as broken.

One more near miss from the same morning: a production validation run had been prepared before the client changed the format, so it still carried the old naming flow. A quick deploy of that validation would have shipped the format the client had just rejected. A passing validation is a snapshot of the source at the moment it ran, not of the decision as it stands now.

A TBD address cannot be scheduled

A property with no street cannot be geocoded, so Field Service should not schedule a visit to it. The obvious place for that guard is a validation rule on ServiceAppointment. It cannot be done there: ServiceAppointment.ParentRecordId is polymorphic, so the formula cannot reach the Work Order’s Location. The guard is a before-save flow, filtered to a scheduled start being set, that queries the parent Work Order and stops the save with a Custom Error element:

force-app/main/default/flows/Service_Appointment_Block_TBD_Address.flow-meta.xml

<customErrors>
    <name>Block_Scheduling</name>
    <customErrorMessages>
        <errorMessage>This property's address is still TBD. Use Confirm Address on the property before scheduling this appointment.</errorMessage>
        <isFieldError>false</isFieldError>
    </customErrorMessages>
</customErrors>

Testing it produced one more searchable error. Updating the same ServiceAppointment instance that the insert returned failed with:

Operation failed due to fields being inaccessible on Sobject ServiceAppointment

ParentRecordId cannot be updated, and the instance still carried it. The test now updates a new ServiceAppointment built with only the Id and the scheduling fields.

Practical summary

  • Lead conversion inserts the Opportunity before an after-save Lead flow can stamp anything on it. Name from those stamped fields on the update, with ISCHANGED in the start element’s filterFormula.
  • Number repeat Opportunities once and store the number. Recounting during a rename gives every record the same suffix.
  • Let one flow own a naming rule. Other flows change a stamp field and let it rebuild.
  • Give records without the data a naming rule needs a deliberate placeholder. A converted Opportunity still named Company- is the convert dialog’s default, which means no automation renamed it: check the Lead’s data before rewriting the flow.
  • In a probe on this org, standard conversion copied the Lead address to Account billing on a new Account and on one with blank billing, and left populated billing alone. Correct billing only while it still matches the Lead address.
  • A picklist used as a marker must have no default, in the value set and in every record type.
  • ServiceAppointment.ParentRecordId is polymorphic: guard scheduling with a before-save flow and a Custom Error, not a validation rule.

Filed under

Disclosure: Doorvana's owner is also a co-owner of Nocona Consulting. This is a real engagement between two separate companies, but not an arm's-length one — and not an independent reference. More on the work page.

FAQ

Can a before-save flow on Opportunity create see fields set by an after-save flow on the converted Lead?

No. Lead conversion inserts the Opportunity first, so a before-save flow that runs only on create sees the record as conversion built it. Anything an after-save flow on Lead writes afterwards, such as a lookup to a property record, arrives as a separate update. To react to it, run the Opportunity flow on create and update and filter the update to the field that was stamped, for example with ISCHANGED in the start element's filterFormula.

What does standard lead conversion do with the Lead address on the Account?

In a rolled-back Apex probe on this org, a new Account got the Lead address as its billing address, an existing Account with blank billing got it too, and an existing Account with billing already populated was left alone. If the Lead address is a job site rather than where the customer is billed, automation after conversion has to correct billing, and should only do so while billing still matches the Lead address.

How do you number repeat Opportunities at the same property without renumbering them on a rename?

Store the number. Counting other Opportunities at the same property and record type gives the right number when an Opportunity is first named, but recounting during a rename gives every Opportunity the same suffix. Save the number in a field such as Property_Sequence__c and reuse it whenever the property and record type have not changed.

Why should a marker picklist have no default value?

Because a default fills the field on every record created by any route, not only the screen that was designed to set it. If automation treats a non-blank value as meaningful, a default makes it true everywhere. Remove the default from the global value set and from each record type's picklistValues, and let the screen flow that owns the field set its own default.

Why is a converted Opportunity named after the company with a dash at the end?

That is the default Opportunity name the lead conversion dialog fills in, the Company followed by a dash. It survives whenever no automation renames the Opportunity after conversion. If your naming flow depends on a field that only some Leads have, such as a property created by a post-conversion flow, the Leads without it keep the default. Check the converted Lead's data before rewriting the flow, and give the no-data case its own name, for example a Property TBD placeholder.

Working on something like this?

I can tell you what it takes.

If you run a home services business and this looks like a problem you have, book a call and we will talk through it.