I am using before update trigger
I want to uncheck checkbox for remaining record in same object if one record checkbox is checked.
trigger trigger_ManagePrimaryMember on Team_Members__c (before update) {
Set<Id> currentprimarymemberid = new Set<Id>();
Set<Id> currentprimarymembrteamid = new Set<Id>();
List<Team_Members__c> teamid =new List<Team_Members__c>();
List<Team_Members__c> Updateprimarymember = new List<Team_Members__c>();
for(Team_Members__c primarymember : trigger.new)
{
currentprimarymemberid.add(primarymember.Id);
}
teamid= [select Id,Team__c from Team_Members__c where Id in :currentprimarymemberid];
for(Team_Members__c teammembers :teamid)
{
currentprimarymembrteamid.add(teammembers.Team__c);
}
for(Team_Members__c teammembers :[select id,Name from Team_Members__c
where Team__c in :currentprimarymembrteamid])
{
if(!currentprimarymemberid.contains(teammembers.id))
{
// making the checkbox to false for other member in the team
teammembers.check_box__c= false;
}
}
}
Thanks in advance