2

Is it possible to add custom objects that have master-detail relationships with other objects that already contain records in Salesforce?

EXAMPLE:

I've uploaded all of my data into the "Contact" object - this includes First Name, Last Name, Address, Total Dollar Amount of Purchases, and Total number of purchases.

The total dollar amount of purchases will be a "roll up" total of each purchase's dollar amount (in a separate "Purchases" object) associated with each individual in the "Contact" object.

The "total number of purchases" will be a "roll up" total of the number of times each individual in the "Contact" object purchased something.

There would be 3 records in the "Purchases" object associated with John Smith, and they are John Smith purchase 1 - $25, John Smith Purchase 2 - $50, John Smith Purchase 3 - $25.

The "Contact Object" would have John Smith - Purchases: 3, Total Dollar Amount of Purchases: $100.

My problem is that when I try to create the "Purchases" object AFTER already uploading all my "Contact" data, I can't make the master-detail relationships necessary for the "Total Number of Purchases" and "Total Purchase Amount" roll ups.

This is because Salesforce tells me that "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 understand that the "easy fix" is just to make both objects from the start and THEN load all my data in after making the master-detail relationships.

However, this poses a problem if I wanted to add and track even more data in newer objects in the future.

For example, what if I decided I wanted to measure a new metric such as each record of an individual opening up a marketing email - with marketing emails in a new object to keep track of the dates, times, and even subject lines of each email?

2 Answers 2

2

Actually, the easy fix is just do what the message says, populate the lookup for the existing purchase records, once all the purchases have a parent you will be able to change the field type.

If you want to add another child object in the future you just need to make sure that from the beginning you populate the lookup field that references the parent record.

0

In Master Detail relationship, parent object does not allow orphaned child records which means every record in the child object must be associated to parent Object. We must create lookup relationship between the child and the parent object. Now populate all child records with a valid lookup field to the parent. Check how to populate child records with a valid field to the parent.

1
  • When we try to create Master Detail relationship usually the above error will not be displayed before creating any records in Child Object. After creating records in Child objects then only Master Detail relationships can not be established between parent Object and Child Object. In Master Detail relationship, parent object does not allow orphaned child records which means every record in the child object must be associated to parent Object. Aug 6, 2017 at 4:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .