I have a form/flow that has three fields Start date/Time, End Date/Time and location. What I want is when the user selects the values for those 3 fields in the form and proceeds, I do a record lookup on all the existing events in Salesforce and a decision element. So if the dates chosen by the user conflicts with any of the existing event in Salesforce, it chooses one path, if no conflict was found, it takes another path in the flow.

For some reason, when I enter dates that conflicts with existing event, even then it does not take the path that it is supposed to choose when a conflict is detected, it always chooses the other path no matter what.

Here are the screenshots of the record lookup. enter image description here

enter image description here

Screenshot of the isthereconflict variable. enter image description here

Here is the screenshot of decision element.

enter image description here

  • Have you tried running your flow in the debugger to see what's happening in your Get Records step? (Click Debug in the upper-right corner of Flow Builder.) Mar 5 '19 at 23:10

The challenge here is that you actually have multiple possible cases to test. (Let's assume that in all cases the location matches.)

  1. The specified start and end times exactly match an existing event or are between the start and end times of an existing event (completely contained).
  2. The specified start time occurs before an existing event's start time, but specified end time is between the existing event's start and end times (overlaps the start).
  3. The specified start time occurs between the start and end times of an existing event, but the specified end time is after the existing event's end time (overlaps the end).
  4. The specified start time occurs before the start time of an existing event, and the specified end time occurs after the end time of the same existing event (exactly matches or overlaps the entire event).

You are only testing the 4th case (specified event starts before and ends after an existing event, or is an exact match since it's GTE/LTE), so any other cases are not being matched. (When I reproduced your criteria/decision, I received exact matches and my decision routed correctly.)

The problem with using Get Records to check this is that it doesn't have the ability to check for custom condition logic, such as (1 AND 2) or (3 AND 4) or (5 AND 6). It can only do all records or an AND on all conditions.

What you might be able to do instead is get all events, loop through them, and then move the decision logic (which does support advanced logic) into the loop. That's not very efficient though.

Slightly more efficient, you could run Get Records additional times with the different sets criteria if no matches were retrieved. So you could use a variable to indicate which criteria you had already checked (assigning a value each time you hit the Decision element) and then rerouting to a different Get Records each time no record was retrieved until finally all four queries had been made. Kind of awkward, and you might find that the overhead to make multiple queries results in a wait.

Other than that, it might be faster and more efficient to use Apex to write a SOQL query and create an invocable action that you can then add to your flow.

  • Thanks for the suggestions. I see what you are saying. I think I kind of like the idea of calling Apex action in case if multiple record lookups do not work. But the issue I am facing right now is that my above code does not detect conflict and never takes the path that it should take if a conflict is detected. Do you think my decision element is checking the conflict correctly?
    – Student
    Mar 6 '19 at 0:47
  • Did you try running it through the debugger to see if Get Records was retrieving any records? I created a similar flow and mine retrieved the record I expected it to get and routed through the decision correctly. Mar 6 '19 at 2:04
  • yes I did run debugger, it said no record retrieved, but as far as I know there was a conflict.
    – Student
    Mar 6 '19 at 3:26
  • OK - if there was no record retrieved, then it's probably not your decision, but rather your Get Records logic. Double check that the values of all your variables are what you expect, and that the event you're expecting to match actually matches. I can't see anything else that might be wrong. Mar 6 '19 at 16:20
  • yes, so looks like I was not selecting the dates properly. It does detect the conflict now :) However, I am really worried as I have four different scenarios to cater in this case that you mentioned above. Is there a way I can just display the real-time calendar to user with the available dates on the calendar and they can pick a date from that ? It will make things very clear and easy to manage.
    – Student
    Mar 6 '19 at 16:41

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.