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
SF Beginner 2019SF Beginner 2019 

getting the value of two check box to account checkbox

HI,

I have this This account and I have a child name renewal.

What i want is that the checkbox(which is a formula field) from the Renewal will be put into account as 2 checkboxes as well.


Wherein will named as renewal 1 and renewal 2 in the Account. How can I build a these in apex, wherein either of the two checkbox from the renewal will be put onto the account as well, but these will check every record of the renewal object, wherein if renewal 1 or renewal 2 isn't check, it will not check the renwal 1 or renewal 2.

ex.

Renewal object.

Record 1, Renewal 1 is Checked
Record 2, Renewal 2 is Not Checked
= Renewal 1 is Checked in Account

Record 1, Renewal 1 is Not Checked
Record 2, Renewal 2 is Checked
= Renewal 2 is Checked in Account

Record 1, Renewal 1 is Checked
Record 2, Renewal 2 is Not Checked
Record 3, Renewal 1 and 2 are not Checked
= Renewal 1 and Renewal 2 are not Checked in Account



Record 1, Renewal 1 is Checked
Record 2, Renewal 2 is Not Checked
Record 3, Renewal 2 is not Checked
= Renewal 1 Checked in Account

Record 1, Renewal 1 is Not Checked
Record 2, Renewal 1 is Not Checked
Record 3, Renewal 2 is Checked
= Renewal 2 are not Checked in Account

Record 1, Renewal 1 is Checked
Record 2, Renewal 2 is Not Checked
Record 3, Renewal 1 and 2 are not Checked
= Renewal 1 and Renewal 2 are not Checked in Account since a record isn't checked either of the two.

meaning if there is missing unchecked on the Renewal, it wil not make either Renewal 1 or Renewal 2 checked.
 
public class Renewal {
    public void GotoAccount(List<Renewal__c> renmem) {
        List<Account> accountsToUpdate = new List<Account>();
        List<Id> renid = new List<Id>();
        Set<Id> ids; 
        
        for(Renewal__c ren : renmem){
                renid.add(ren.Account__c);
                }
        
        renmem = [SELECT Id, Renewal1__c, Renewal2__c, Renewal__c.Account__c,  FROM Renewal__c WHERE Id IN :renmem];
		
        for (Renewal__c p : renmem ) {
           IF(( /*What Condition */))
                accountsToUpdate = new List<Account>();
                ids = new Set<Id>(); 
                if(!ids.contains(p.Account__c)){
                    Account a = new Account(
                        Id = p.Account__c,
                        Renewal1__c = p.Renewal1__c,
                        Renewal2__c = p.Renewal1__c);
                    ids.add(p.Account__c);
                    accountsToUpdate.add(a);
                }
           }
          
        update accountsToUpdate;
        
    }
}