Loading

Unable to create a master-detail relationship

Publish Date: May 24, 2026
Description

In Salesforce, when you attempt to create a Master-Detail relationship on a custom object that already contains data records, Salesforce prevents the relationship from being saved. This occurs because a Master-Detail relationship adds a new required field (the foreign key) to the custom object, and every existing record must have a valid value in this field. Records with blank values in the new required field fail validation, blocking the relationship creation.
This article is not applicable to custom metadata types.

Resolution

To create a Master-Detail relationship on a custom object that already has data, use the following workaround: create a Lookup relationship first, populate the foreign key field on all existing records, and then convert the relationship to Master-Detail.

Option 1 — Delete Existing Data (if few records exist)

If the custom object does not yet have many records, delete the existing data, create the Master-Detail relationship, and then re-import the data with valid parent record values.

Option 2 — Convert via Lookup (to preserve existing data)

This approach preserves all existing records:

  1. Create a Lookup relationship (instead of Master-Detail) on the custom object. This adds the new foreign key field without making it required. Do not mark the Lookup as required.
  2. Populate the Lookup field on every existing record with a valid parent record ID. You can use Data Loader for bulk updates if the object has many records.
  3. Once all records have a value in the Lookup field, edit the object relationship and change the relationship type from Lookup to Master-Detail.

Note: This workaround is not applicable for custom metadata types.

Knowledge Article Number

000385231

 
Loading
Salesforce Help | Article