@W-20921403: Smart Lookup Resolution for Mixed Salesforce IDs and Local References#3946
Merged
aditya-balachander merged 2 commits intomainfrom Jan 28, 2026
Merged
Conversation
dipakparmar
pushed a commit
to ClaritiSoftware/CumulusCI
that referenced
this pull request
Feb 12, 2026
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a Snowfakery recipe contains multiple instances of the same Salesforce object where:
SalesforceQuery.find_recordfor a lookup field (returns a real Salesforce ID)reference:for the same field (returns a local ID)The
--generate-cci-mapping-filecommand creates a single mapping step with that field marked as alookup. This causes CumulusCI data load failures because the pre-resolved Salesforce ID fromfind_recordcannot be resolved through the ID table lookup mechanism—it returns NULL, resulting inREQUIRED_FIELD_MISSINGerrors.Example Recipe
Generated SQL
What Happened Before This Fix
The lookup resolution performed a LEFT OUTER JOIN on the ID table:
Pricebook2Id = '1'): Match found → correct SF ID returned ✓Pricebook2Id = '01sSG00000Dsd89YAB'): No match → returns NULL ✗Result:
REQUIRED_FIELD_MISSING: Required fields are missing: [Pricebook2Id]Solution
Implemented "smart lookup" resolution that detects when a value is already a valid Salesforce ID and uses it directly instead of attempting ID table lookup.
Changes
1.
cumulusci/tasks/bulkdata/query_transformers.pyAdded helper functions to detect valid Salesforce IDs:
Modified
AddLookupsToQuery.columns_to_addto use a CASE expression:2.
cumulusci/tasks/bulkdata/load.pyRegister the custom SQLite function when initializing the database:
How It Works Now
The generated SQL query now uses a CASE expression:
Pricebook2Id = '1'): ID table match found → uses resolved SF ID ✓Pricebook2Id = '01sSG00000Dsd89YAB'): No ID table match, but value is valid SF ID → uses original value ✓