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
kpriya Aggarwalkpriya Aggarwal 

Can anyone help me on this? How can I achieve this requirement?

I have a custom picklist field name Status__c and its values : Active & Inactive  on Account. Whenever I select Active value then other records should be change to Inactive.

Suppose I have 10 records in Account object. According to the requirement, So if I update one record with Active value then other 9 records should be update to Inactive?

Thanks
Narender Singh(Nads)Narender Singh(Nads)
Hi,
You will need a trigger to achieve this functionality. Your trigger will look something like this:
trigger UpdateAccStatus on Account (after update) {
    
    list<id> AccIds=new list<id>();
        for(account a:trigger.new){
            if(a.status__c=='Active')
                AccIds.add(a.id);
        }
    
    Account[] Acclist=[select id, status__c from account where ID not in :AccIds];
    Account[] ListToUpdate=new account[]{};
    for(account a:Acclist){
        a.status__c='Inactive';
        ListToUpdate.add(a);
    }
    update ListToUpdate;
    
}

Let me know if it helps
Thanks
Sampath SuranjiSampath Suranji
Hi,
Use update trigger and avoid the recursively update,
trigger UpdateAccStatus on Account (after update) {
    boolean needToUpdate=false;
    list<id> AccIds=new list<id>();
    for(account a:trigger.old){
    System.debug('old status ='+a.status__C);
         if(a.status__c!='Active'){
            System.debug('a.id ='+a.id);
                AccIds.add(a.id);
                needToUpdate = true;
         }
     }     
     
    if(needToUpdate ){
        
         Account[] Acclist=[select id, status__c from account where ID not in :AccIds];
         for(ID existId: AccIds){
             checkRecursive.SetOfIDs.add(existId);
         }
         
         Account[] ListToUpdate=new account[]{};
         for(account a:Acclist){
            If(!checkRecursive.SetOfIDs.contains(a.Id)){
                a.status__c='Inactive';
                ListToUpdate.add(a);
                checkRecursive.SetOfIDs.add(a.Id);
            }            
        }
        update ListToUpdate;
    }
   
    
}
 
public class checkRecursive {
     public static Set<Id> SetOfIDs = new Set<Id>();
}

Regards
Sampath​