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
radanradan 

How to move a detail record from one master to another?

In our application, an use case calls for a detail record (with notes, attachments etc.) to be moved from one master record to another. This is very easy to do with a Lookup relationship; but we have to use Master-detail for various reasons. 

 

Currently I am cloning the detail record (and all Notes..) and creating a new detail record and adding it to the new master. This has a undesirable side effect of changing the time stamps and LastModifiedBy, CreatedBy,.. system fields. 

I would like to be able to preserve these attributes. 

 

Is there a way to accomplish this? 

ahab1372ahab1372

are you doing this in a trigger or a class?

 

Did you try just to change the Master-Detail field to the Id of the new parent record?

 

Pseudocode:

 

detailRecord.Master__c = newMasterRecord.Id;

 

 

 

radanradan

I am doing this in an apex class. 

What you are suggesting is the crux of the issue.

If you try to change the Master reference of the Detail record and do an Update, you will get a DML exception. 

David81David81

Unfortunately, Detail records in a Master-Detail relationship cannot be reparented.

 

In my opinion, it's a "feature" that severly limits the use of Master-Detail relationships. I want the Roll-Up Summary fields, but also might need to reparent the Detail records. Can't have both it seems...