You need to sign in to do that
Don't have an account?
Rafa Federer
Can some one suggest how we can do the following code : Account and Opportunity related trigger
We have a parent object ABC which has a checkbox parent checkbox , we have a child object obc which has a checkbox child checkbox .
child checkbox needs parent checkbox to be checked in order to be checked .
The situation i have is when that is done we shld not allow the parent checkbox to be unchecked when trying to and should give an error.
child checkbox needs parent checkbox to be checked in order to be checked .
The situation i have is when that is done we shld not allow the parent checkbox to be unchecked when trying to and should give an error.
you need to try below trigger for achieve your requirment.
what work this trigger is do.
This trigger will excute when Account(Parent) record will come for insert or update and if isParentCheckBox__c field is checked then it will be checked all Child(Opportunity) records isChildCheckbox__c field check and if user try to uncheck isParentCheckBox__c then it wil be throw an error message.
//here is trigger
if you satisified with my code then don't forget to mark it as best answer.
I believe you will be marked it as best.
Thank you
Second part i have written this way :
Can you suggest how i could avoid the nested for loop here ????
set<id> accountid = new set<id> ();
for(account accrecords: trigger.new)
{
accountid.add(accrecords.id);
List<Opportunity> opty = new List<Opportunity>();
opty = [ select id . accountid , childcheckbox__c from opportunity where accountid in: accountid];
for(Opportunity optyrec: opty)
{
if(optyrec.childcheckbox__c == true)
{
if(accrecords.parentcheckbox__c == false)
{
accrecords.adderror('cannot uncheck ');
}
}
}
}