I have ParentObject__c that has ChildObject__c, and there's a field Payment__c on ParentObject that gets updated in several different ways based on the values in both ParentPicklist__c on ParentObject and ChildPicklist__c on ChildObject. There are nine different variations of how Payment calculates based on the values in those two picklists.
I've had some success with Workflow Rules. Payment calculates based on currency fields on both ParentObject and ChildOject. I created 6 RollUp Summary fields on ParentObject that are each not blank if ChildPicklist is set to a certain value, so that I can run the workflow rules based on RollUpSummaryX != 0 and ParentPicklist = VALUE. There are 9 workflow rules activated.
Everything runs correctly if there's a change to ParentObject, but if there's a change to ChildPicklist, then the workflow rules don't run until ParentObject gets edited and saved once again, even though the value in the ParentObject's RollUpSummaries have changed. I even tried adding a workflow rule to ChildObject that would affect a field on ParentObject every time ChildObject was modified, just to try and trigger the workflow rules to run.
Am I making sense? How can a change to ChildObject trigger workflow rules on ParentObject?
I first tried a simple Apex Trigger, my first trigger I've made, and was able to get it to work in theory, but the problem was that it runs before update, and so when the ParentPicklist value changes, the Payment field doesn't change until ParentObject is edited and saved AGAIN. So the failure of the workflow rules is better than this failure.
Should I try with a Trigger once more, and is there a way to reference the value in a field that is about to be saved and use that to determine the way the trigger runs? (i.e. beforeUpdate check value of ParentPicklist)
Or should I create the workflow rule or trigger on the ChildObject, and if I do that, what happens if there's a change on the ParentObject, will it trigger a workflow on ChildObject?