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
Fahad MatinFahad Matin 

there is a checkbox in contact object , the requirment is you must have to check true for any one record, but you can not check more than one record

Fahad MatinFahad Matin
// in contact obj there is a field IsChecked__c
// this check box should be checked for any one record not more than
//  this check box should be checked for atleast one record you can not uncheck for all record


public class checkBox_helper {
    public static void PrimaryCheckbox(list<contact> triggerNew){
        list<contact> conList=[select id,IsChecked__c from contact where IsChecked__c=true];
        boolean checkedTrue=false;
        for(contact con:triggerNew){
            if(con.IsChecked__c==true && conList.size()>0){
                checkedTrue=true;
            }
        }
        if(checkedTrue==true){
            for(contact co:conList){
                co.ischecked__C=false;
            }
            update conList;
        }
    }
}
Suraj Tripathi 47Suraj Tripathi 47
Hi Fahad Matin,
Please describe your requirement clearly
What is your condition to update that field as true?

Thank you!

Regards,

Suraj Tripathi