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
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
RKSalesforceRKSalesforce
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
		accountIds.add(acc.Id);
    }
	for(AccEmployee__c accEmployeeRecord:[Select id, Account__c, Active__c from AccEmployee__c Where Account__c IN :accountIds]){
		accEmployeeRecord.Active__c = False;
		accEmployeesToUpdate.add(accEmployeeRecord);
	}
	
	update accEmployeesToUpdate;
}

Please mark as best answer if helped.

Regards,
Ramakant