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
Rupeshk67Rupeshk67 

how to create toggle with one checkbox field only

Hi Guys,
i have a rquirement where according to status of child object , toggle should be ON/OFF on parent object.

problem is i have many status values on child object and accordingly it should on/off the toggle.

i am planning to create separate checkboxes for different value . is there any other way to do it ??

Please let me know. Thanks
Suraj Tripathi 47Suraj Tripathi 47
Hi RupeshK67,
Here is the solution:
Please take reference of below code:

Apex trigger:
trigger Casetrigger on Case (after insert,after update) {
    if(trigger.isAfter && (trigger.isInsert || trigger.isupdate)){
        Updatetoggle.setcheckbox(trigger.new);
    }
}

Apex Class:
public class Updatetoggle {
    public static void setcheckbox(List<case> caselist){
        Set<Id> accountidset = new set<Id>();
        for(Case caseobj:caselist){
            accountidset.add(caseobj.AccountId);
        }
        List<Account> acclist= new List<Account>();
            for(case caseobject:caselist){
                Account acc = new Account();
                acc.Id = caseobject.AccountId;
                if(caseobject.Status =='Closed'){
                    acc.Closed__c= true;
                    acc.Working__c= false;
                     acc.escalated__c= false;
                }else if(caseobject.Status =='Working'){
                    acc.Working__c= true;
                     acc.escalated__c= false;
                    acc.Closed__c= false;
                }else if(caseobject.Status =='Escalated'){
                    acc.escalated__c= true;
                     acc.Working__c= false;
                     acc.Closed__c= false;
                }
                acclist.add(acc);
            }
        update acclist;
    }

}

Thanks