You need to sign in to do that
Don't have an account?
Arnold Joseph Todas
How can i retain checkbox in parent ?
Hello,
How can i retain checkbox in parent, I have picklist in child containing ('a','b','c','d','e'). I created a child with a picklist of 'a' and it should checked on parent and i delete the child, the checkbox 'a' of parent should be uncheked . the main problem is if i created another child that contains picklist 'a', and i delete the first child which is picklist 'a' the checkbox of parent will retain because there is another child that i created with picklist 'a' . how can i create a trigger for that?
Thanks for help!
AJ
How can i retain checkbox in parent, I have picklist in child containing ('a','b','c','d','e'). I created a child with a picklist of 'a' and it should checked on parent and i delete the child, the checkbox 'a' of parent should be uncheked . the main problem is if i created another child that contains picklist 'a', and i delete the first child which is picklist 'a' the checkbox of parent will retain because there is another child that i created with picklist 'a' . how can i create a trigger for that?
Thanks for help!
AJ
Can you confirm one thing like you want only one check box for pick list a or 5 check box for a,b,c,d,e .Please confirm .
I have 5 checkbox for A B C D E on picklist.
Below trigger will work for checkbox A and picklist A ,Try to implement for next four .
trigger ParentCheckBox on Child (After insert ,After update,After delete ,After undelete) {
Map<id,String> idpicklistvalueMap=new Map<Id,String>();
if(Trigger.isInsert || Trigger.isUpdate || Trigger.isUndelete){
for(Child chd : Trigger.new){
if(chd.ChildChekbox__c != null){
idpicklistvalueMap.put(chd.AccountId,chd.ChildChekbox__c);
}
}
}if(Trigger.isDelete){
for(Child chd : Trigger.old){
if(chd.ChildChekbox__c != null){
idpicklistvalueMap.put(chd.AccountId,chd.ChildChekbox__c);
}
}
}
List<Parent> patListToUpdate=new List<Parent>();
for(Parent pat :[SELECT id,(SELECT ChildChekbox__c FROM Contacts WHERE ChildChekbox__c='A') FROM Parent WHERE id IN : idpicklistvalueMap.keySet()]){
if(pat.ChildRelationshipName.size() > 0){
Parent prt=new Parent(id=pat.Id,ParentChkBox__c=true);
patListToUpdate.add(prt);
}else{
Parent prtt=new Parent(id=prtt.Id,ParentChkBox__c=false);
patListToUpdate.add(prtt);
}
}
try{
update patListToUpdate;
}catch(DMLEXception de){
System.debug(de);
}
}
Any issue let me know .
Do one thing in all cases just pass the account id set from trigger to handler class method ,and apply the logic .
try below code it will work ,
I'm using triggerhandler for that, i'll try converting and i let you know if there are some bugs
Thanks
AJ
It's not unchecking when i delete both child.. i created two child which is picklist of grab, and i delete it both the checkbox in parent should be uncheck how can i fix that bug?
Thanks!
AJ