You need to sign in to do that
Don't have an account?
sonam guptha
trigger to make value as zero if no values present no child records present on it
HI
Below is my trigger iam counting child records based and prinitng on parent object,but one error iam seeing if there are no child objects with that picklist value still its showing count as 1,i wanted to show the value as zero,if no records present on it,please help me out
Below is my trigger iam counting child records based and prinitng on parent object,but one error iam seeing if there are no child objects with that picklist value still its showing count as 1,i wanted to show the value as zero,if no records present on it,please help me out
trigger requirementsTrigger on Requirements__c (after insert, after update) { List <Id> progIds = new List<Id> (); List <Programs__c> programs = new List<Programs__c>(); List <AggregateResult> requirements = new List<AggregateResult>(); for(Requirements__c req:trigger.new){ progIds.add(req.Programs__c); } programs = [Select Id, Count__c From Programs__c Where Id In :progIds]; requirements = [Select Programs__c, Count(Id) From Requirements__c Where Programs__c IN: progIds AND Waived__c = 'Yes' AND Status__c IN ('Active') Group By Programs__c]; for(AggregateResult ar: requirements){ for(Programs__c p:programs){ if(ar.get('Programs__c') == p.Id){ p.Count__c = Decimal.ValueOf(String.ValueOf(ar.get('expr0'))); } } } update(programs); }
please add below debug and check value once.
system.debug('===='+Decimal.ValueOf(String.ValueOf(ar.get('expr0'))))
Please add program to list and update the list.
programs.add(p);
update programs;
Thanks
Varaprasad
on the above trigger am i following all the best practices,can you please have a look?
And any solution for to make the value zero