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
Naveena P 10Naveena P 10 

Hey Everyone I have a question , I have MDR and I wish to delete parent record but the child data is required for me . So without losing the child records data can I delete Parent ? If so how ?

AnudeepAnudeep (Salesforce Developers) 
Hi Naveena, 

Child records will automatically be deleted when the parent record is deleted in a master detail relationship. This is by design and unfortunately there isn't any configurable setting to avoid this. 

Child records will no longer be automatically deleted when the parent record is deleted only if you detach a master-detail relationship

The best way to handle this is to have a validation rule in place to prevent deletion of dhild in Master-Details

See this example: https://learn-force.com/2017/07/19/validation-rule-to-prevent-deletion-of-child-in-master-details/

Please mark this answer as best if you find this information helpful. It may help others in the future. Thank You!

Anudeep
Sachin HoodaSachin Hooda
Hi Naveena, 
If the relationship between those objects is of Lookup type. Deleting the parent wouldn't affect its child records. So either you can switch the relationship to Lookup. If that is not possible in your use case.
Another workaround would be a before delete trigger. You can have a trigger that takes the child data from the parent record and inserts it as a new record.
trigger keepChildRecords on ParentObj__c (before delete) {
       List<ChildObj__c> childList = new List<ChildObj__c>();
      Set<Id> childIdList = new Set<Id>();
        for (ParentObj__c pr : Trigger.old)
        {
            if(pr.childrName__c != null){
             childIdList.add(pr.ChildrName__c);
            }
        }
        childList = [Select Id, someField__c From ChildObj__c Where ID IN:childIdList];
        //make sure not to query parent relationship while querying for child. 
        List<ChildObj__c> newChilds = new List<ChildObj__c>(); //to keep the data of the child records
        for(childObj__c cr : childList){
        newChilds.add(cr.clone(false));
         }
INSERT newChilds;
}
I wouldn't say it is the best approach. But it still gets your work done.
I hope it helps you, if you still have any query please post them here. 
Naveena P 10Naveena P 10
Let me put my question this way then , my lead is owner of MDR Records and he is leaving the organisation so in order not to get records deleted what should be my approach ?
AnudeepAnudeep (Salesforce Developers) 
You can try removing the Delete object level permission for the Master object for the appropriate profiles, removing the delete button from the pagelayout will not restrict User completely from deleting the Record ,the User can still delete the Records from the list view