I have a two Parent objects. There is a junction between these two objects (not via master detailed but lookup).
I need to implement a custom rollup of these child records on the parent object.
In the trigger logic i do the following:
trigger on Child_Object ( before insert ) {
helper(trigger.new);
}
Below is the helper logic:
helper(list<childObject> childlist) {
list<Id> parentID = new list<ID>();
// DO SOME PROCESSING HERE.
for ( childObject cvar : childlist ) {
parentId.add(cvar.parent_lookup__c);
}
// I HAVE DONE SOME PROCESSING ON THE PARENT RECORD ROLLUP AND UPDATING PARENT RECORDS.
IF (parentList.size() > 0)
update(parentList);
}
I am having a validation on the Parent that is restricting the update, which should not allow insertion of the child and fail the child records.
Unfortunately, I am unable to capture the error in the helper class using try and catch and show exception message on the child record on creation.
Could you please help me form a solution for the same.
Even tried using "database.SaveResult[]", but this fails since I am unable to capture the child reference in the saveResult as the action I update the parent and parent records fail.
How do i find the corresponding child that is causing the error.
TIA.