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
Jonathan Anspaugh 6Jonathan Anspaugh 6 

Control a checkbox with value from multiple related records

I need to solve a process automation issue. Right now I have a checkbox field called 'Can Contact' on the Contact and a custom object related to the contact via lookup field. What I need to do is:

A) Check the box on the contact is ANY of the related records has a 'Can Contact' that is 'true' 
--- This is already done and working properly through Process Builder

B) Uncheck the box on the contact if ALL of the related records have 'false' values for their field. 
--- This is where it is not working.

While the Process Automation works for A, I know I likely need to convert A & B into a trigger but am not sure where to begin or how to formulate the trigger since there are potentially multiple associated records to search.

My fields are:

Contact.Can_Contact__c
UHCU_Accounts__c.Can_Contact__c

Again the logic is:
A) If ANY related UHCU Account is checked, then check the Contact field.
B) If ALL related UHCU Accounts are not checked, then uncheck / have a non-checked field on the Contact

Any help would be greatly appreciated.