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 a trigger on Contact checking if Status = Yes //and Type= 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
Best Answer chosen by Laxmi SFDC
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Laxmi,

Can you try the below trigger on Contact object.

Here I craeted Checkbox_field__c on Account object
trigger CheckBoxOnAccount on Contact (after insert,After Update) {
    Set<Id> accountids= 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(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(acctoupdate.size()>0)
    update acctoupdate;
        
    }
    }
}

Let me know if you face any issues.

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

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Laxmi,

Can you try the below trigger on Contact object.

Here I craeted Checkbox_field__c on Account object
trigger CheckBoxOnAccount on Contact (after insert,After Update) {
    Set<Id> accountids= 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(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(acctoupdate.size()>0)
    update acctoupdate;
        
    }
    }
}

Let me know if you face any issues.

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

Thanks,
This was selected as the best answer
Laxmi SFDCLaxmi SFDC
Hi
Thank u so much.....