Simple question probably. Imagine a use case where, I need to have the highest amount value from all associated Opportunity rolled up onto a field on the Account.
I am aware about the bulkification practice. Where you include a for loop, that iterates through trigger.new. But how would I do this? Logically, I imagine:
- Trigger on opportunity
- For loop starts...
- Inside For loop, I have to look for all associated opportunities for the current opportunity's account (but that is SOQL inside FOR loop).
I know that is bad. So, what is the practice in handling such situations?
Ignore the possibility of using Roll Up Summary. This is not the exact use case. But it reflects the need I have in authoring code.