function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anthony DuncanAnthony Duncan 

Master Detail Relationship Question

Objective: The object you created for the previous challenge is pretty handy. Imagine how much more useful it would be if brokers could specify which client made an offer and which property the client wants to buy. Add two relationships to the Offer object so brokers can capture this data in Salesforce. Create a Master-Detail relationship with the Property object and a Lookup relationship with the Contact object.
On the Offer object, add a Master-Detail relationship to the Property object named Property

Error Message Received: 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. 
NagendraNagendra (Salesforce Developers) 
Hi Anthony,

Master - Detail relationship requires that the Detail Record (Child) ALWAYS have a Master (Parent) record since the detail record inherits security and ownership from the parent record.

Therefore, if you want to create a Master - Detail relationship between existing objects, you need to make sure that all the existing records for the child object have a lookup value to the parent object BEFORE you can create the Master Detail relationship.
 
1. Create a lookup from the child object to the parent object.
2. Populate ALL the records with a valid lookup value to the parent.
3. Change the Lookup relationship to a Master - Detail relationship. This is only allowed if ALL RECORDS HAVE A VALID LOOKUP. Otherwise, you'll get the error you describe.
 
The Master-Detail relationship is covered in detail in the Certification Exam and is in the Developer Guide (Chapter 3). Hope this helps.

Please mark this as solved if the information helps so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra
Maricor Roth 8Maricor Roth 8
This helped!  Thanks!  
NagendraNagendra (Salesforce Developers) 
Hi Roth,

Glad that it's resolved.

May I request you please mark this as solved so that others can get benefited out of this who are facing a similar issue.

Thanks,
Nagendra