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
GSBassoGSBasso 

How to initialize Date variable in flow?

Anyone able to successfully initialize a Date variable at the start of a Flow either using <apex:param> in a Visualforce page or by passing an interview map when constructing a Flow instance within an Apex controller (as per this page)?

I get an error with either technique. When I use <apex:param> it complains that the types don't match.

The only thing that works is initalizing through the URL itself.

I even tried to initialize using a string date (i.e. yyyy-DD-mm), just like with the URL technique. Specifically,  I made the controller property bound to <apex:param> a String type, and for the interview map I used a string value rather than a Date object. But these made no difference.
GSBassoGSBasso
For posterity I've managed to get the Date initialization to work both through <apex:param> and by explicitly creating the flow within the constructor of the Apex controller class for the Visualforce page in which the flow is contained.

To get the <apex:param> technique to work I ended up creating a new Date variable. Not sure what was wrong with the variable I had been using but this might be a last resort for others to try if they run into similar odd behaviours.

Getting the other technique of passing in an instance of Map<String, Object> to the flow constructor was a lot trickier.It seemed the issue had to do with a property I had defined that referenced the flow. This property was bound to the finishLocation attribute of the flow:interview component.
public class MyController
{
    public Flow.Interview.SomeFlow aFlow {get; set;}

    public MyController()
    {
        Map<String, Object> interviewMap = new Map<String, Object> {
            'varDate' => System.today()
        };
        this.aFlow = new Flow.Interview.SomeFlow(interviewMap);
    }

    public PageReference finishPage
    {
        get
        {
            // flow instance was referenced within this block
        }
        set;
    }
}
The solution was to replace the finishPage property with a getfinishPage method, the code for which was basically what I had in the property get method. Why this worked and the above did not I have no idea.