function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ekmekm 

How do I cast Flex date into Salesforce when running query on selected dates?

Hi,

I've been attempting to query SalesForce data based on a range of ActivityDates.

Here's an example where I force the dates and everything shows up fine for this forced date range.

Within my apex.query, I have the following:
("Select field1, ActivityDate From Event where ActivityDate >= 2008-08-01 and ActivityDate <= 2008-09-30;

Now what I'd like to do is capture dates from a start and end dateField base my query off of those dates.

What is the approach I should take? Cast the Flex date I capture into Salesforce as a string or date? I've tried capturing the dateFields on a change event and setting the value to a string.
I've also tried converting the string to a Date (i.e., var dStartSearchBroker:Date = DateField.stringToDate(wholeStartDate, "YYYY-MM-DD") ) where wholeStartDate is the string value that I've originally set on the change event. Still no luck.

Any help that someone could provide would be greatly appreciated.

Regards,

EKM
devNut!devNut!
Write a function to translate a flex date into the date format required by salesforce.
ekmekm
Thanks, devNut for your response. The question I'm really trying to learn though is what exactly is the date format I need to use to query the ActivityDate field in Salesforce. I'm still not finding the format in any of the SalesForce documentation or examples.

I'm able to create an Event using the following for field ActivityDateTime: new Date(2008, 08, 01, 0, 0, 0);
Therefore, when querying ActivityDate, I would think I would be able to use the following format:
var myNewDate:Date = new Date(2008, 04, 30) and insert the variable myNewDate into the following query.
apex.query("Select Id, ActivityDate From Event where ActivityDate >= myNewDate")
But I receive no values when I know they do exist.

However, the following does work: apex.query("Select Id, ActivityDate From Event where ActivityDate >= 2008-04-30")

The over all goal is to query Events based on a range of dates.
devNut!devNut!
A couple things:

1) myNewDate should not be part of the string since it is a variable

e.g.
pex.query("Select Id, ActivityDate From Event where ActivityDate >= "+ myNewDate)

2) myNewDate probably needs to be a string of format yyyy-mm-dd
ekmekm
Success! Thanks for helping me work through this!

I had tried using string variables before but instead used the following query code:
"Select Id, ActivityDate From Event where ActivityDate >= '" + myTestString + "'",

Here's the working code:

Using 2 string variables, I'm able to query a range of dates:
var myTestString:String = '2008-06-30';
var myTestString2:String = '2008-10-30';

"Select Id, ActivityDate From Event where ActivityDate >= " + myTestString + " and ActivityDate <= " + myTestString2,

Thanks again!