2

I was wondering what would be the most efficient way to do the following.

The Account object is the parent of the Order object.

The Order object has a field called 'Status'.

The Status field, a drop down field, has several values.

The Account can have many Order records (one-to-many relationship).

I need to check for every Account that I pass from a Set collection the following.

If all Order records that are children of an Account have the Status = 'Completed', move those Accounts to another Set collection.

What will be the best way to do this?

Regards.

1

The first thought that comes to me is to have two rollup summary fields (via standard rollups, or declarative rollups). One to count the number of Orders under a given Account, and another one to count the number of Orders which are complete.

With that, the logic that you're looking to implement becomes trivial (for all accounts in trigger.new, check to see if Count1 == Count2. Put into one set if true, the other set if false).

  • Thanks for your response Derek. The part you are mentioning I already have in place exactly as you are suggesting. What puzzles me is how can I check if all Orders related to an Account have their Status set to Completed. That is what I'm missing in my code. – Carlos Naranjo Mar 22 '17 at 18:34
  • @CarlosNaranjo I don't understand what you're stuck on. If you have one summary field that counts all Orders, and a second summary field that counts only Orders where Status == 'Complete', then checking if all Orders related to the Account are complete is simply a matter of checking if account.<Count of All Orders> == account.<Count of Completed Orders>. Are you asking about how to get the count of completed orders? – Derek F Mar 22 '17 at 18:38
  • if you had to code this by using maps or use the declarative rollups, what would you feel is the best option considering efficiency and stability? – Carlos Naranjo Mar 24 '17 at 8:04
  • @CarlosNaranjo The DLRS tool is fairly widely used, and has been around for a number of years, so I'd say that would be the more stable option. Efficiency should be about the same. The only real downside to using DLRS is that it creates a separate trigger. If you're looking to adhere to the idea of "One Trigger per Object", then you might need to integrate the trigger generated by the DLRS tool (at the cost of losing the ability to declaratively modify the rollup). DLRS tool may also not work too well if you're using a trigger framework. – Derek F Mar 24 '17 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.