No — you cannot create a Master-Detail relationship directly on an object that already has data. Salesforce blocks it because Master-Detail is a required relationship: every child must have a parent. If existing records would be created with null parents, the platform refuses to make the field.
The workaround is well-known and widely used: create the field as a Lookup first, backfill every record, then convert to Master-Detail.
Why the platform blocks direct creation
A Master-Detail relationship is implicitly required (no nulls allowed) and gives the parent cascade delete and roll-up summary authority. If existing children had no parent, you’d have orphan rows that violate the relationship’s own definition — and the moment you tried to save such a record, the platform would error out. Rather than leaving you with unsavable data, Salesforce refuses to create the field at all.
The error you see is along the lines of:
“You can’t create a master-detail relationship because there are existing records of this object.”
The standard workaround (4 steps)
Step 1 — Add a Lookup
Create the field as a Lookup relationship pointing to the target parent. Lookups allow nulls, so existing data is fine.
Step 2 — Backfill every child record
This is the critical step. Every single child record must have its new lookup populated. Use whichever tool fits the data:
- Data Loader with a CSV mapping child Id → parent Id
- Data Import Wizard for simple cases
- Flow / Process to derive the parent from existing fields (e.g., match on Account name)
- Apex anonymous script for complex matching logic
- Manual for tiny data sets
Verify completion with:
SELECT COUNT() FROM Child__c WHERE Parent_Lookup__c = null
This must return 0.
Step 3 — Verify other prerequisites
- Child has fewer than 2 existing master-details (Salesforce allows max 2 per object)
- Child has no sharing rules you need to keep (those will be removed)
- Child’s OwnerId-dependent logic is reviewed (OwnerId disappears after conversion)
Step 4 — Convert Lookup → Master-Detail
In Setup → Object Manager → [Child Object] → Fields & Relationships → [Your Field] → Edit, change the field type from Lookup to Master-Detail. Salesforce runs a pre-conversion check; if anything’s still wrong, it tells you. Save.
The field is now master-detail. Children are tightly coupled to parents, cascade delete is enabled, and you can create roll-up summary fields on the parent.
End-to-end example
“Your org has 100,000
Invoice_Line_Item__crecords that were originally standalone. You now need to relate them toInvoice__cas master-detail so you can roll up Total Amount.”
- On
Invoice_Line_Item__c, add Lookup fieldInvoice__c→Invoice__c. - Identify the parent Invoice for each existing line item. Maybe you have an
Invoice_Number__ctext field on each line — match againstInvoice__c.Nameto find the parent record Id. - Build a CSV:
LineItemId, ParentInvoiceId. - Use Data Loader to update the 100,000 rows.
- Run
SELECT COUNT() FROM Invoice_Line_Item__c WHERE Invoice__c = null→ confirm zero. - Convert the Lookup field on
Invoice_Line_Item__cto Master-Detail. - On
Invoice__c, create the roll-up summary:Total_Amount__c = SUM(Invoice_Line_Item__c.Line_Total__c).
Done. The platform recalculates roll-ups on the next save of any line item.
What about deletion?
If you can’t backfill some records — e.g., they’re truly orphans with no logical parent — delete them. Then run the count check, then convert. Don’t try to skip backfill by setting the records to a “dummy parent” that doesn’t exist; that fails at insert validation.
What if you only have a tiny number of records?
Same workflow, but step 2 might just be manual editing through the UI. The rule is the same: every child must have a parent before conversion.
Things people forget
- OwnerId disappears after conversion. Any code, report, or flow referencing the child’s OwnerId breaks. Audit first.
- Sharing rules on the child are removed. If a sharing rule was the only way certain users saw certain children, those users lose access on the master’s terms.
- Workflow / Flow actions that set the lookup to null fail after conversion — Master-Detail can’t be null.
- External integrations that create child records without a parent fail — fix the integration to always pass a parent.
Bottom line
You can’t go from “no relationship” to “master-detail” in one step on an existing populated object. The path is always: add Lookup → backfill → convert. Plan the backfill carefully — that’s the work.
Verified against: Salesforce Help — Master-Detail Relationship Considerations. Last reviewed 2026-05-17.