Hi, by using trigger we can stop the prevention of Parent record if it's having child records. please correct me if it is wrong public class preventhandler {
public static void doprevent(list newlist){ set accId=new set(); list oplist=[select Id,AccountId from Opportunity]; for(Opportunity op:oplist){ accId.add(op.AccountId); } for(Account a:newlist){ if(accId.contains(a.Id)){ a.addError('You cant delete'); } }
Hey hii, actually any kind of cascading delete does not triggers the trigger at all, this means if u have m-d relation and if you delete parent and it delets child then in that case it wont execute the trigger of child at all
Great job 👏 thanks for sharing
Welcome 😄
Really this content is very helpful 😊
Thank You👍
Thanks
nice effort buddy
Thanks 😄
How did you know about the RaisePlatformEvents interface? Do you follow release notes regularly? If yes, any resources that you can suggest?
I actually keep on reading documents alot, and thats where i came to know about them, ill keep updating on this channel as soon as i find something
Hi,
by using trigger we can stop the prevention of Parent record if it's having child records. please correct me if it is wrong
public class preventhandler {
public static void doprevent(list newlist){
set accId=new set();
list oplist=[select Id,AccountId from Opportunity];
for(Opportunity op:oplist){
accId.add(op.AccountId);
}
for(Account a:newlist){
if(accId.contains(a.Id)){
a.addError('You cant delete');
}
}
}
}
trigger preventTrigger on Account (before delete) {
if(trigger.isBefore && trigger.isDelete){
preventhandler.doprevent(trigger.old);
}
}
Hey hii, actually any kind of cascading delete does not triggers the trigger at all, this means if u have m-d relation and if you delete parent and it delets child then in that case it wont execute the trigger of child at all