Ask Search:
Heather MickeyHeather Mickey 

How to calculate MAX DATE over multiple records, not child related (Flows Loop?)

Looking for some mega-expert advice. :D

Goal: Populate Account Object/Field "Last Call Date" with MAX Call Date of Submitted Calls.

Setup:
Call has a look-up relationship to Account, therefore Summary fields are not an option
Account has custom Last Call Date field
Call has the standard Create Date, Modify Date and a custom Call Date field
A User should submit Calls sequentially which means the most recent Submitted Call record 'should' be the most recent Call Date, but this isn't always the case. Therefore the solution I had found in other posts doesn't work: http://www.salesforceweek.ly/2015/02/how-to-flow-most-recent-record.html   **It really only works on most recent record, not this additional field (Call Date) I need to consider.

The post has me thinking this could be done in a Process Builder & Flow combo, although I'm a new at Flows and am stumped.

Process Builder:
When a Call is Submitted, Launch the Flow & send over the Variable for the Account ID (associated to the Call).

Flow:
Fast Lookup: Lookup the Call object where the Account ID matches the Account ID Var passed from Process Builder and where Call Status = Submitted.
Save the Call Date and ID in the CallsforAccount SObject Collection Variables.
>>I believe this should be looping through all Submitted Calls for the Account triggered and storing the two variables.

After this, I'm lost how to complish the rest. I think that I would need to Loop through the SObject Collection Variables and somehow find the Max Call Date. Then, once having gone through all Calls and determined the Max Call Date, Update the Account object Last Call Date field with the Max Call Date value.

Am I correct in my logic? How would I complete this in Flows? I truly appreciate your time in helping me out. I've search just about every post out there...
 
Best Answer chosen by Heather Mickey
Ahilesh RagavanAhilesh Ragavan
Hi Heather,

You are almost there. Looping all the related Call records is the right approach.

I can give you some pointers on the logic inside the loop to be implemented.
  1.     Create a sObject variable recentCallDate.
  2.     Loop all the Call records with a Loop element.
  3.     Within the Loop, Use a Decision element to compare the variable recentCallDate with the Call Date field of     iterated Call record.
  4.     Store the most recent date of the two into the recentCallDate variable with an Assignment element.
  5.     After your loop finishes, you should have your most recent rate in the recentCallDate variable.

Hopefully this is what you are looking for.

Thanks,
Ahilesh

All Answers

Ahilesh RagavanAhilesh Ragavan
Hi Heather,

You are almost there. Looping all the related Call records is the right approach.

I can give you some pointers on the logic inside the loop to be implemented.
  1.     Create a sObject variable recentCallDate.
  2.     Loop all the Call records with a Loop element.
  3.     Within the Loop, Use a Decision element to compare the variable recentCallDate with the Call Date field of     iterated Call record.
  4.     Store the most recent date of the two into the recentCallDate variable with an Assignment element.
  5.     After your loop finishes, you should have your most recent rate in the recentCallDate variable.

Hopefully this is what you are looking for.

Thanks,
Ahilesh
This was selected as the best answer
Heather MickeyHeather Mickey

Thank you @Ahilesh Ragavan for your advice.
I seem to be stuck at #3. When I am in the Decision, I only have the Operator options of equal, does not equal or is null. I've read online that I should be able to have other options for Dates which would allow me to compare greater than/less than, so maybe I have done something incorrectly in populating my variables? (The field in SFDC is a Date field.)
User-added image
Looking forward and thankful for your advice.

Thank you,

Heather

Heather MickeyHeather Mickey
@Ahilesh Ragavan -- I discovered what I was doing wrong. I didn't realize I could select the field inside of the LoopedCalls reference in the Resource. Ignore me for now... I'm continuing to work on the solution. :D
Heather MickeyHeather Mickey
Got it working. Thanks so much for your help @Ahilesh Ragavan !
Ahilesh RagavanAhilesh Ragavan
Glad it worked !!