+ Start a Discussion
kvingupta1.2949876275969072E12kvingupta1.2949876275969072E12 

Cannot Create Master-Detail Relationship - Not sure how to rectify the problem

Hi All,

 

I am trying to create a new master detail relationship between two custom object names order and supplier. I have added 100 records in order object so far. Now when I go to add a master object  supplier.  I am receiving following error.

 

Cannot Create Master-Detail Relationship 

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.    

 

I followed the message and  added   supplier as a lookup table and populate all the records.  now  when I try to change the fieldtype I don't see any option of changing this as a master detail type.

 

Can any body help me knowing the exact  reason and solution 'coz creating and adding record again would be a problem?  

 

Best Answer chosen by Admin (Salesforce Developers) 
sandeep@Salesforcesandeep@Salesforce

You have done job very close what you want. Now you need to first of all fill all lookup field valuse for all 100 records of order then you will get option to convert this lookup in Master Detail relation ship. 

 

Note : This option was not  coming because there are some records where this lookup field is having no reference of Supplier ( Master)  and no child can exist without Master record.

All Answers

AroraAnupAroraAnup

Whenever you do a Master-Detail relationship between 2 objects in Salesforce.com,  the relationship requires that the Detail Record (Child) SHOULD ALWAYS have a Master (Parent) record. This is because firstly, the Master is always REQUIRED in order to create a Detail record and also becuase 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.

In your case, I believe what you can do is that an extract of the data using the data loader, establish the relationship between the 2 objects (lookup), upload the data back in the system and the change the relationship.

 

You may want to refer to the Force.com Workbook to understand Object Relationships in detail.

 

Hope this helps!

sandeep@Salesforcesandeep@Salesforce

You have done job very close what you want. Now you need to first of all fill all lookup field valuse for all 100 records of order then you will get option to convert this lookup in Master Detail relation ship. 

 

Note : This option was not  coming because there are some records where this lookup field is having no reference of Supplier ( Master)  and no child can exist without Master record.

This was selected as the best answer
souvik9086souvik9086

We all know that Master field is a mandatory field in master-detail relationship. So when you created the lookup relationship make sure that you filled up the master field in all the records. then you surely get the option of converting to Master-Detail relationship.

 

If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.

Thanks

sandeep@Salesforcesandeep@Salesforce

As I think All are tuned on same way so please check your answere if it met yout expectation so we can close this discussion and let me know if  you need some thing which is not discussed yet.

kvingupta1.2949876275969072E12kvingupta1.2949876275969072E12

Thanks to all for the reply, so after populating the records  I am able to chnage relationship in to the master-detail type. So my main problem is resolved though I see one unusaual behaviour with product object.

 

When I try to add the product object as a master in my order object I was not able to change in the master-detail type even after populating all the records with lookup in the order object.

so does bydefault product object does work and I need to create the new one?