+ Start a Discussion
Stuart FlemingStuart Fleming 

pass dateTime parameter to Apex Query

Hi.  I have created a flow that shows a number of orders that a person is making.  The first thing the flow does is assign the flow {!$Flow.CurrentDateTime} to a variable called NowVariable.  The next screen the user enters the order.  The final screen the user sees a lightning component table that shows the orders the person made (passing in the contact and NowVariable).  The lightning component controller is an apex class:

  public static List<ice_Cream_Order__c> getIceCreamOrdersByContactTime(Id contactId, DateTime createdWhen){

      return [  select Id, How_Many__c , Ice_Cream_Flavor__r.Name, Contact__c  ,  Contact__r.Name
                FROM ice_Cream_Order__c 
                 where Contact__c = :contactId AND createdDate >= :createdWhen];

At issue:  The table shows no data.  I assume it is an issue of the Flow DateTime value of 2018-06-18T15:42:53.986Z does not correspond to the apex sql.    

Would anyone have any suggestions on how to pass the dateTime variable to the apex method?

Stuart FlemingStuart Fleming
I found a bug perhaps.  When I assign the {!$Flow.CurrentDateTime}  to a variable and show it in the flow (on a screen) I see this value:
6/18/2018 2:02 PM

I also have that value showing on the lightning component ( passed using the lightning component DESIGN page).  
I show it on the lightning component as:
 <p class="slds-p-horizontal--small"> This is the Lightning Component time: {!v.DateTime} </p>

And this is the value I get:  This is the Lightning Component time: 2018-06-18T18:02:20.270Z

I am not exactly sure why it is being passed as 18:02:20.270Z....which is the time in iceland.

So my I suspect my query is getting zero records due to the fact that the date/Time passed is 
4 hours in the future.

FROM ice_Cream_Order__c
WHERE LastModifiedDate> 2018-06-18T18:02:20.270Z

(yes I am testing on a dummy table called ice_Cream_Order__c). What can I say, I like ice_Cream!