RunFromApex Doesnt work in UPSERT Context #286
Replies: 1 comment 4 replies
-
Hi @jayeshtejwani, converting this to a discussion as I don't have reason to believe (yet) that there's any issue with Apex Rollup at play here:
All of that being said - since you're updating the records in memory (prior to presumably committing them to the database with the updated amounts?), if you absolutely had to call Apex Rollup without letting your trigger handler framework call Apex Rollup: you can still do that. I described how you would go about doing so in the email chain we've had together; namely, calling global static Rollup runFromApex(
List<Rollup__mdt> rollupMetadata,
Rollup.Evaluator eval,
List<SObject> calcItems,
Map<Id, SObject> oldCalcItems) {
// ...
} At the moment that method is safeguarded from external entry points that are not trigger-based, but I could overload this method to allow for non-trigger-based invocations. I am just not sure it makes sense to do so, and in that I beg your pardon because it could just be that I haven't gotten enough information from you to understand why you would want to circumvent the traditional method for calling Apex Rollup - namely, via Record-Triggered Flow or from an Apex trigger. Again, I'm open to exposing another method to allow you to do this more easily, but I'd like to understand the use-case prior to doing so since the base
|
Beta Was this translation helpful? Give feedback.
-
Hi James,
As per our discussion, I have used runFromApex from my queueable framework, but I have encountered an issue.
I am using custom metadata to calculate sum of opportunity amount on the Account annualrevenue field.
In the After Update trigger context, I pass the updated opportunities(amount is changed) to runfromapex, it runs an insert operation(adds the value to annual revenue) and doesn't upsert or recalculate. I am passing the After_Update context so it should run an update operation right?
My Code:
RollUp.runFromApex(rollUpData.opportunities, TriggerOperation.AFTER_UPDATE);
Secondly,
I have a scenario, where I have 2 different amount fields on opportunity and two different custom roll-up fields on the account. I would like to run the rollup calculations only on field value changes using custom metadata when anyone of the amount fields on Opportunity changes. So the conclusion I would to know if there is a method I can use where I can pass which custom metadata to be used when any one of the fields changes? also, pass the context of after update to update the amount?
Beta Was this translation helpful? Give feedback.
All reactions