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
Linga_RaminLinga_Ramin 

Parent Record Child Record Update

I have One Object HDS which is self lookup. It has records and 
    if record 1 is checked all the records below of record record 1 is checked automatically , and if record 2 is checked all the records below record 2 is checked automatically.
Sajid Ali 20Sajid Ali 20
Trigger updateAllChild on HDS__c (after update){

Set<Id> ParentHDSId = new Set<Id>();
Boolean parentCheckedValue = '';

for(HDS__c parentHds : Trigger.New){

if(Trigger.oldMap.get(parentHds.Id).ParentCheckedFieldName__c != parentHds.ParentCheckedFieldName__c && parentHds.ParentCheckedFieldName__c !=null){
    ParentHDSId.add(parentHds.Id);
    parentCheckedValue = parentHds.ParentCheckedFieldName__c;    
}
}

if(ParentHDSId.size() > 0){

List<childHDS__c> childHDSList = new List<childHDS__c>();
List<childHDS__c> toUpdatChildHDSList = new List<childHDS__c>();
childHDSList = [Select CheckedFieldName__c from childHDS__c where ParentHDS__c IN :ParentHDSId];

for(childHDS__c chHDS : childHDSList){

chHDS.CheckedFieldName__c = parentCheckedValue ;
toUpdatChildHDSList.add(chHDS);

}
if(toUpdatChildHDSList.size() > 0){
    update toUpdatChildHDSList;
}
}


I hope that your requirement is fullfilled.
Thanks