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
Gage Staruch 9Gage Staruch 9 

How to write an else if trigger with checkboxes?

Hey everyone,

I'm trying to write a trigger where if any of the follwing checkboxes are checked off:

Active_1__c 
Active_2__c 
Active_3__c
Active_4__c 
Active_5__c 
Active_6__c 

It marks a separate checkboxed called 

Active_main__c

and if all the checkboxes are unchecked, so is Active_main__c.

 

Can someone help with this? I'm new to the developer space.

Best Answer chosen by Gage Staruch 9
Rahul.MishraRahul.Mishra
Hi,
You can write the trigger like this:
trigger UpdateCheckBoxValue on ObjectName(before insert)

	for(ObjectName obj : trigger.new) {
		if(obj.Active_1__c && obj.Active_2__c && obj.Active_3__c && obj.Active_4__c && obj.Active_5__c && obj.Active_6__c)
			obj.Active_main__c = true;
		else
			obj.Active_main__c = false;
	}
}

Replace the ObjectName with the name of object where you want to write the trigger.
Mark answers best if it does help you.

Thanks,
Rahul