My child object already have 2 Master detail fields on it so I am unable to create 3rd one. I want functionality like Master detail. If user deletes any of parent record on parent object all the child records should be deleted.

  • Cascade delete. It can be enabled if you contact salesforce -- help.salesforce.com/… – kurunve Apr 29 '20 at 16:43
  • I am creating a demo application in trailhead playground – Ansar Saeed Apr 29 '20 at 16:45

A simple trigger will suffice

trigger MyTrigger on Parent__c (after delete) {
 delete [SELECT Id FROM Child__c WHERE ParentId__c = :Trigger.old];
  • In delete event, Trigger.old is only available – kurunve Apr 29 '20 at 18:47
  • 1
    @kurunve - sheesh - epistemic arrogance on my part - fixed – cropredy Apr 29 '20 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.