What needs to happen? What data do you need to retrieve using COQL? Order of operations. What updates? Conditional logic?
Using Deluge, and more specifically, COQL (who would have guessed?), we need to then retrieve all Deal records that were closed (successfully, not lost) in the last 365 days. There are two criteria in there:
We also need a way to group all of those records together by Account. That means we need to actually pull Account info in. We really just need the Name and ID though.
So, let’s pull that info in (JOIN via the Account Name lookup field) and then Order By Account Name. All fields retrieved will be:
We can then use a series of ‘for each’ and ‘if’ statements to add up the Deal Sizes by Account and run the corresponding updates in the CRM Account records (using the IDs we pulled).
Essentially, within the ‘for each’ loop for all of the deals we pull, ordered by account, we need to run a check for if the deal we’re cycling through is for the same account as the previous one.
Set a dealCount variable to 0 and for each deal we cycle through, add 1 to that variable. We also need to check how many deals there are total.
We set a totalAmount variable to 0 outside the loop.
We’ll grab the first (the 0’th) deal and its corresponding account and set that as the account name to start.
Then, we start adding the Deal Amount to the totalAmount variable.
If the account name for a deal is the same:
If the account name for a deal is different:
If the deal we’re cycling through is the last deal in the list (if dealCount variable = the total deal count):