Sub topic 8
Converting a relationship and what can block it
This chapter assumes you can create lookup and master-detail fields in Object Manager. It also assumes you know how roll-up summary fields and inherited sharing work in master-detail. Conversion changes behavior, so check those two areas before you change a live field.
Why convert
Requirements change. A lookup that began as an optional link may need to become a required parent with roll-ups. A master-detail that proved too strict may need to become a lookup so child records can exist alone. You can edit the field type in place, so you don't need to delete the field and rebuild it. Salesforce checks a set of conditions first, and the conversion is blocked if any fails.
Lookup to master-detail
Master-detail makes the parent required, so every existing child record must already have a parent.
- Find child records with an empty lookup.
- Fill in each one, or delete the records you don't need.
- Edit the field and change its type to master-detail.
Use SOQL to find the blanks. This example uses a hypothetical Invoice__c child object with a lookup field Customer__c.
SELECT Id, Name
FROM Invoice__c
WHERE Customer__c = nullIf the query returns rows, the conversion will fail until you fix them.
Other things to check:
- Object type. The child (detail) must be a custom object. A standard object cannot be the detail side of a master-detail relationship.
- Limits. A custom object can have at most two master-detail fields. If it already has two, you cannot add a third by converting.
- Ownership. The detail record stops having its own owner, because it inherits ownership and sharing from the master. Any code, report, or sharing rule that relies on the child's
OwnerIdneeds review.
Master-detail to lookup
This direction is blocked mainly by roll-up summary fields. A lookup cannot support native roll-up summary fields, so every roll-up on the master object that summarizes this child must be deleted first.
- List the roll-up summary fields on the master that summarize this child.
- Delete them, or replace the logic. An Apex aggregate query is one replacement. Flow or a trigger also works.
- Change the field type to lookup.
After conversion, the parent is no longer required, and deleting a parent no longer deletes its children. Sharing for the child also becomes independent of the parent. Salesforce also restricts some conversions on junction objects, so check the current documentation before converting one of their master-detail fields.
Blockers at a glance
| Direction | Blocked when | How to clear it |
|---|---|---|
| Lookup to master-detail | Some child records have a blank lookup | Populate or delete those records |
| Lookup to master-detail | The child is a standard object, or already has two master-detail fields | Not fixable by editing the field |
| Master-detail to lookup | The master has roll-up summary fields on this child | Delete the roll-ups and replace the logic |
Decision flow
Practical advice
Test the conversion in a sandbox first. Then review sharing, because moving to master-detail changes who can see child records. Moving to lookup can also change who can see them. Check automations that depend on required parents or on cascade delete.
Exercise
A custom object has a lookup to Account. Your conversion to master-detail fails. Name the most likely cause and the fix. Then name the blocker you would hit going the other way if Account had roll-up summary fields on this object.
Show answer
The most likely cause is child records with an empty lookup value. Query for them with WHERE Account__c = null, then populate or delete them and convert again. Going the other way (master-detail to lookup), roll-up summary fields on the master block the conversion. You must delete or replace them first.