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
Nani SircillaNani Sircilla 

Create master-detail relationship on existing records

Hi All,

I have two custom objects like Student__c(Detail) and Batch__c(Master). I had created lookup field for Batch__c on Student__c and added some records. But now i want to change lookup field as master detail.

For that i have populated the lookup field with data in all records of Student__c and trying to change the relationship type to Master-Details.
but still getting same 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. "

Please post the appropriate answer..

Thank you.
Nani.

 
Tejpal KumawatTejpal Kumawat
Hello Nani,

You need to create the lookup, then populate each one so that each child record has a parent record. This is because a master detail relationship does not allow for 'orphaned' child records. Once you have a lookup with each child having a parent, than you can go back and convert the lookup field to a master detail. 

follow this url : https://success.salesforce.com/answers?id=90630000000h0TaAAI

If this answers your question then hit Like and mark it as solution!

 
Tejpal KumawatTejpal Kumawat
Hello Nani,

If this answers your question mark Best Answer it as solution, It will help others!
Cyrus TalladenCyrus Talladen
The reason you are getting that error is because you have records that are already reflecting the lookup relationship.  One option is for you to delete all the records that have that relationship with the other objects with type object that you want the master detail.  Another is to delete the lookup which you are trying to change to Master-detail.


Cyrus Talladen
www.levementum.com
David Roberts 4David Roberts 4
What do you mean by "delete the lookup"?
I have a custom object with many records related to the account through a lookup. All the objects have an account entry. I can't change it from lookup to master-detail.
Waseem Pasha 4Waseem Pasha 4
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.   Click here to return to the previous page.  
Waseem Pasha 4Waseem Pasha 4
Iam uanble to complete the trail head due to the error msg above????
Paresh KoshtiParesh Koshti
First You need to create the lookup on that field
then edit each record and fill the fields on which you have lookup relationship in the object
then go to the  Custom Fields & Relationships of an object and edit the lookup relationship fields then click on change field type button and select master-Details and save it 
Nubes Elite Technologies Pvt. LtdNubes Elite Technologies Pvt. Ltd
Can this process be automated ?