Wednesday, 5 July 2017

 Tricky Error : Cannot Create Master-Detail Relationship

                                        Great things are done by a series of small things brought together. 
                                                                                                                         -Vincent Van Gogh


Some times we will get below error message while creating master detail relationship..

whats that error massage?

"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. "

Have you encounter this error before then its great!!!!. Today I'am going to explain solution about that error

Tricky solution:

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.

Use this query to confirm to check if child record exist arent:
SELECT count()  from Child_object__c;


For detailed Information Visit Below Link:
http://www.tutorialkart.com/salesforce/cannot-create-master-detail-relationship/