You cannot create a new Master-Detail relationship on an existing custom object if records already exist
While creating a Master Detail relationship between two objects, Salesforce can display this error: “You cannot create a new Master-Detail relationship on an existing custom object if records already exist. You must first create a Lookup relationship, populate the lookup field with data in all records, and then change the relationship type to Master-Detail”.
This happens because a master-detail relationship does not allow orphaned detail records. If records already exist in the child object, Salesforce must know which parent record owns each child record before the field can become master-detail.
The practical fix is to first create a lookup relationship, populate the lookup value for every existing child record, and then convert the lookup relationship into a master-detail relationship.
Why Salesforce blocks a new Master-Detail relationship when child records already exist
In a master-detail relationship, the detail record depends on the master record. The master controls ownership and sharing behavior for the detail record, and the detail record cannot exist without a related master record. Because of this, Salesforce cannot safely create a required master-detail field on an object that already contains records unless every existing record has a valid parent value.
A lookup relationship is more flexible. Existing child records can temporarily have a blank lookup value. After every child record is updated with a parent value, Salesforce can convert the lookup field into a master-detail field.
- Master-detail relationship: every detail record must have a master record.
- Lookup relationship: the lookup value can be blank unless the field is made required.
- Conversion from lookup to master-detail is allowed only after the lookup field is populated for all existing child records.
Example: Hospital as parent object and Invoice as child object
Example :- Creating Master Detail Relationship Between Hospital (Parent Object)and Invoice Object(Child Object).
In this example, the Invoice object already has records. If we try to create a master-detail relationship directly from Invoice to Hospital, Salesforce displays the error because the existing Invoice records do not yet have a required parent Hospital record.
To solve it, use this order:
- Create Lookup Relationship between Hospital and Invoice Object.
- Edit all Invoice records and enter Hospital object(Parent Object field).
- Now Change lookup relationship to Master Detail relationship.
Here we have already created some records in Child Object let us try to create Master Detail relationship between Invoice Object and Hospital Object.
Attempting to create the Master-Detail field on the existing Invoice object
Go to Setup | Build | Create | Object | Select Child Object (Invoice) | Fields and Relationships | New
Click on Master Detail relationship and click on next button.
Enter Related object as Hospital. Click on Next button.
As shown above, Salesforce does not allow us to create the master-detail relationship directly because Invoice records already exist. We must first create a lookup relationship between the two objects, fill that lookup value on every existing Invoice record, and then change the field type to master-detail.
Creating the temporary Lookup relationship before converting to Master-Detail
- Click on view field and create new lookup relationship field.

We have successfully created Lookup relationship field in Invoice Object.

We have created Lookup relationship field in Invoice Object.
Populating the Hospital lookup value on every existing Invoice record
Before changing the relationship type, each existing Invoice record must point to one valid Hospital record. If even one Invoice record has a blank Hospital lookup value, the conversion to master-detail can fail.
- Now go to Invoice Object

- Click on Invoices as shown above.

- Now the list of records that are present in Invoice Object will be displayed. Now click on any record and edit the record as shown below.

We have created Lookup relationship field in Invoice object but in Invoice record the master object field is empty. Now we have to populate all child records with a valid lookup field to the parent.
- Now double click on the Hospital field as shown below.

- Click on Lookup button and select Hospital as shown below.

- Like wise Edit all Child record and populate all the records with lookup value.

- Now click on Save button.

- As shown above we have successfully populated value for INVOICE – 001.
Repeat the same update for every existing Invoice record. For a small number of records, manual editing is enough. For many records, use Data Loader, Data Import Wizard, list views, or another controlled data update process so that every record has the correct Hospital value before the relationship is converted.
Changing Lookup Relationship to Master Detail Relationship.
After all child records have a parent value, open the lookup field and change its field type to master-detail.
Go to Setup | Build | Create | Object | Child Object (Invoice) | Hospital | Edit.

- Now click on Change Field Type button as shown below.
- Select data type as Master Detail Relationship as shown below.
- And Finally Click on Save button as shown below.
Successfully we have created Master-Detail relationship in Salesforce as shown below.
Things to check before converting Lookup to Master-Detail in Salesforce
- Check that every existing detail record has a valid parent record in the lookup field.
- Confirm that the selected parent object is the correct owner of the child record’s lifecycle.
- Review sharing and security impact because master-detail detail records inherit access from the master record.
- Check whether roll-up summary fields are needed on the master object after conversion.
- Review delete behavior because deleting the master record can delete related detail records.
- Test the conversion in a sandbox when the object contains important business data.
Salesforce Master-Detail relationship limits and restrictions to remember
A child object can have a limited number of master-detail relationships. Salesforce commonly supports up to two master-detail relationships on a custom object, and master-detail relationships also count against relationship field limits. Always check the current Salesforce documentation for the exact limit in your edition and object type.
- You cannot create a master-detail relationship if existing detail records do not have parent values.
- You may need to use lookup first and then convert it to master-detail.
- Some standard objects cannot be used in every master-detail configuration.
- Master-detail relationships affect ownership, sharing, roll-up summaries, and delete behavior.
- A detail object cannot always be reparented unless reparenting is enabled where Salesforce allows it.
For reference, Salesforce explains object relationships in its official documentation: Relationships Among Objects. Salesforce also documents the lookup-to-master-detail conversion requirement in this help article: Unable to create master-detail relationship field.
Common reasons the Lookup to Master-Detail conversion still fails
If the conversion still does not work after creating the lookup field, check the data and object setup again. The most common cause is still blank lookup values on one or more existing child records.
- Blank parent values: At least one child record does not have a Hospital value.
- Wrong parent object: The lookup was created to the wrong object or field.
- Data import issue: Some records were missed during the update or failed during import.
- Relationship limit reached: The object has reached the allowed number of relationship fields or master-detail relationships.
- Business rule conflict: Validation rules, automation, or required fields may prevent record updates before conversion.
QA checklist for this Master-Detail relationship error fix
- Confirm the child object name in the article matches the object where the error appears.
- Verify that the tutorial explains why existing child records must have parent values.
- Check that the steps clearly follow this order: create lookup, populate lookup, convert to master-detail.
- Confirm that the screenshots still match the described Salesforce setup flow.
- Check that readers are warned about sharing, delete behavior, and relationship limits before conversion.
FAQs on the Salesforce error: You cannot create a new Master-Detail relationship on an existing custom object if records already exist
How do I create a master-detail relationship between existing records?
Create a lookup relationship first, populate that lookup field on every existing child record with a valid parent record, and then change the lookup field type to master-detail.
Why does Salesforce ask me to create a lookup relationship first?
Salesforce asks for a lookup relationship first because existing child records may not yet have parent values. A lookup field can be populated gradually, but a master-detail field requires every detail record to have a master record.
How many master-detail relationships can you have on an object?
A custom object commonly supports up to two master-detail relationships. Because limits can vary by object type and Salesforce release, verify the current limit in Salesforce setup or official Salesforce documentation before designing the data model.
Can we create a master-detail relationship on standard objects?
Master-detail relationships are usually created with custom objects, and standard object support depends on the specific parent-child combination allowed by Salesforce. Check the field creation options available on the object in Setup.
What is the main limitation of master-detail relationship in Salesforce?
The main limitation is dependency. The detail record depends on the master record for ownership, sharing, and lifecycle behavior. This is useful when the child record should not exist alone, but it is not suitable when child records must remain independent.
Conclusion
We have practically learnt how to create Master detail Relationship between two objects when an error like “You cannot create a new Master-Detail relationship on an existing custom object if records already exist. You must first create a Lookup relationship, populate the lookup field with data in all records, and then change the relationship type to Master-Detail” occurs.
The important rule is simple: existing child records must not be left orphaned. Populate the temporary lookup field for every child record first, then convert the lookup relationship to a master-detail relationship after the data is complete.
TutorialKart.com





