You need to sign in to do that
Don't have an account?
ravikanth321
Check Parent(Account) checkbox(Active ) when any one of child(Child__c) records checkbox(Primary) is checked(We also have a validation where only one chilld record can have that checkbox checked)
Check Parent(Account) checkbox(Active__c ) when any one of child(Child__c) records checkbox(Primary__c) is checked(We also have a validation where only one chilld record can have that checkbox checked) ....Uncheck Checkbox Active__c if checkbox primary__c is unchecked.
01trigger Primarycheck on Child__c(after insert, after update) {
02 list<Account > listofParentObjToUpdate;
03 set<Id> setOfids = new set<Id>();
04 Map<Id,Child__c> mapIdVschild = new Map<Id,Child__c>();
05
06 for(Integer i=0;i<Trigger.new.size();i++){
07 if(Trigger.new[i].Primary__c==true || Trigger.new[i].Primary__c==false){
08 mapIdVschild.put(Trigger.new[i].Child__c,Trigger.new[i]);
09 }
10 }
11
12 if(!mapIdVschild.isEmpty()){
13 list<Account> listOfParentObj = [select id,Active__c from Account where Id IN: mapIdVschild.keySet()];
14
15 listofParentObjToUpdate = new list<Account>();
16 for(Account parent : listOfParentObj) {
17 parent.Active__c=mapIdVschild.get(parent.id).Active__c;
18 listofParentObjToUpdate.add(parent);
19 }
20 Update listofParentObjToUpdate;
21 }
22}
01trigger Primarycheck on Child__c(after insert, after update) {
02 list<Account > listofParentObjToUpdate;
03 set<Id> setOfids = new set<Id>();
04 Map<Id,Child__c> mapIdVschild = new Map<Id,Child__c>();
05
06 for(Integer i=0;i<Trigger.new.size();i++){
07 if(Trigger.new[i].Primary__c==true || Trigger.new[i].Primary__c==false){
08 mapIdVschild.put(Trigger.new[i].Child__c,Trigger.new[i]);
09 }
10 }
11
12 if(!mapIdVschild.isEmpty()){
13 list<Account> listOfParentObj = [select id,Active__c from Account where Id IN: mapIdVschild.keySet()];
14
15 listofParentObjToUpdate = new list<Account>();
16 for(Account parent : listOfParentObj) {
17 parent.Active__c=mapIdVschild.get(parent.id).Active__c;
18 listofParentObjToUpdate.add(parent);
19 }
20 Update listofParentObjToUpdate;
21 }
22}
Can you please explain the scenario need to implement here.
Thanks,
Gaurav