[SalesForce] Adding Custom Objects + Master-Detail Relationships then Rolling Up Objects That Already Contain Data

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?

Best Answer

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.

Related Topic