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
sam patilsam patil 

help me to write test class on this trigger

#triggerHandler
public static void SetState(list <Child__c> childnewlst){
        set<id> parentids= new set<id>();
       
        for(Child__c child : childnewlst ){
            parentids.add(child.parent__c);
        }
        list<parent__c> parentlist = new list <parent__c>();
       
        if(!parentids.isEmpty()){
        
           parentlist=[select id,state__c, (select id, state__c from child__r where state__c != null) 
                                    from parent__c where id in : parentids];
        }
        list<parent__c> parenttoupdate = new list <parent__c>();
        
        for(parent__c parent : parentlist){
            string state ='';
            
            if(!parent.child__r.isEmpty()){
                for(child__c child : parent.child__r){
                    if(!state.contains(child.state__c)){
                    state = state + child.state__c + ';';
                    }
                    
                }
                parent.State__c = state;
                parentToUpdate.add(parent);
                
            }
            if(!parentToUpdate.isEmpty()){
                update parentToUpdate;
            }
        }
    }

}
PriyaPriya (Salesforce Developers) 

Hey Sam,
Hope you are doing good.
Have you made any attempt for writing a test class for this ?
If Yes, kindly share here, we can help you anywhere needed.

Thanks & Regards,

Priya Ranjan

sam patilsam patil
@PRIYA
can you plese share code ,