0

I am looking to build a new flow to look at a collection of custom object child records (Opportunity_Contact__c) that are linked to Opportunity and determine the highest/max value for a date field called Opportunity_Contact.Contacted_Date__c every time an Opportunity record is created/edited.

Is this possible using Flow? And would anyone have any examples?

I'm new to flow and not quite sure how to get started.

1

Yes, it's possible with declarative automation, but with a couple of caveats -

  1. Flow/Process Builder might not be the best/easiest tool for the job. Is Opportunity_Contact__c Master-Detail? If so, a Roll-Up Summary Field might do the trick with nothing further required. If it's a Lookup relationship, Declarative Lookup Rollup Summaries could do this for you. (And DLRS automatically handles events like record merges for you).
  2. When your Opportunity is first inserted, you won't have any children to inspect at the time of insert. You'd need to be looking at the children when they are inserted.

It doesn't make sense to me to run the process at the time of editing an Opportunity (rather than editing or inserting an Opportunity_Contact__c). However, if that's your required design, you would use a Process Builder on Opportunity to start an autolaunched Flow, passing the Opportunity Id as a parameter.

The flow would then do a Fast Lookup of Opportunity_Contact__c records attached to that Opportunity. It would have a variable (call it Max_Date or something), and would iterate in a Loop element over the Opportunity_Contact__c sObject collection variable. For each element, it would compare the date on that Opportunity_Contact__c to Max_Date and set Max_Date to whichever of the two is higher.

The loop's end connector would go to an assignment of Max_Date to a field on the parent Opportunity where that date belongs, and then to a Fast Update element.

I would suggest, though, that the Process Builder starting this flow off belongs on the child object, Opportunity_Contact__c. The structure of the Flow would look pretty much the same, but Process Builder would pass it the Id of the Opportunity_Contact__c's parent Opportunity to kick it off.

| improve this answer | |
  • Your suggestion does make sense. What I have so far is a "Fast Lookup" element on Opportunity_Contact__c containing a variable called "MaxDate" followed by a "Loop" element to iterate through other Opportunity_Contact__c records over an sObject collection variable called "OppContacts". For the next step, would I build a "Decision" element to compare dates between the current Opportunity_Contact__c record and the "MaxDate" variable to identify which is higher? I'm unclear how to do this. – CDG Jul 14 '18 at 0:20
  • Yes, I think that sounds appropriate. It's hard to visualize flows from description. – David Reed Jul 14 '18 at 1:37

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.