+ Start a Discussion
Radha Rathinavel PandianRadha Rathinavel Pandian 

after delete to uncheck the checkbox

Hi ,
I have to uncheck the checkbox on child object when my parent object record gets deleted.

Parent object : raddes have a some records
Child Object : radparent

I have a check box on radparent. now, my requirement is when i deleted a parent record in raddes the checkbox on child object "radparent" should uncheck which mean we need to check the size of the object and update the child update checkbox.
Best Answer chosen by Radha Rathinavel Pandian
Hi Radha,

You can achieve this by using trigger.
In my case I am taking -------------------   Parent = Account and Child = AccEmployee__c (Relationship Lookup). You need to change Object Names and fields in the below code.
trigger updateChildsOnParentDelete on Account (before delete) {
    set<Id> accountIds = New set<Id>();
	List<AccEmployee__c> accEmployeesToUpdate = New List<AccEmployee__c>();
	for(Account acc : Trigger.old) {
		//Write your Logic here
	for(AccEmployee__c accEmployeeRecord:[Select id, Account__c, Active__c from AccEmployee__c Where Account__c IN :accountIds]){
		accEmployeeRecord.Active__c = False;
	update accEmployeesToUpdate;

Please mark as best answer if helped.