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
Laxmi SFDCLaxmi SFDC 

Create check box field on Account Create new two fields on Contact Status(Picklist)(Yes,No), Type(Active,Active) Create a trigger on Contact checking if Status__c= Yes and Type__c= Active then update checkbox field should be true

Hiiii,

Create check box field on Account

Create new two fields on Contact Status(Picklist)(Yes,No), Type(Active,Active)

Create a trigger on Contact checking if Status__c= Yes and Type__c= Active then update checkbox field should be true

if they're not meeting the criteria we need to update that checkbox as false
Best Answer chosen by Laxmi SFDC
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Laxmi,

Can you try the code below on Contact.
 
trigger CheckBoxOnAccount on Contact (after insert,After Update) {
    Set<Id> accountids= new Set<Id>();
    Set<Id> accountidfalse= new Set<Id>();
    List<Account> acctoupdate= new List<Account>();
    for(Contact con: Trigger.new){
       
        if(con.Status__c=='Yes' && con.Type__c=='Active' ){
          accountids.add(con.AccountId)  ;
        }
        
        if(con.Status__c!='Yes' || Con.Type__c!='Active'){
           accountidfalse.add(con.AccountId);	 
        }
    }
    if(accountids.size()>0)
    {
        List<Account> acclist=[select id,Checkbox_field__c  from Account where Checkbox_field__c =false ];
    
    if(acclist.size()>0){
        for(Account acc:acclist){
            acc.Checkbox_field__c=true;
            acctoupdate.add(acc);
        }
    }
        }
     if(accountidfalse.size()>0)
    {
        List<Account> acclist1=[select id,Checkbox_field__c  from Account where Checkbox_field__c =True ];
    
    if(acclist1.size()>0){
        for(Account acc:acclist1){
            acc.Checkbox_field__c=false;
            acctoupdate.add(acc);
        }
    }
        }   
  
if(acctoupdate.size()>0)
    update acctoupdate;
        
    
    
}

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,