I find this to be odd, not sure if this is a known issue or if it is something I just have to convert but I have a flow that calls a apex process plugin class.

The flow takes a variable of type Date and passes that value to the apex class.

enter image description here

The apex class looks like this:

public with sharing class CreatePaymentSchedule implements Process.Plugin {
    public Process.PluginResult invoke(Process.PluginRequest request) {
        Map<String, Object> result = new Map<String, Object>();
        Date varStartDate = (Date) request.inputParameters.get('varStartDate');
        return new Process.PluginResult(result);

When I run the flow, I get this error:

EXCEPTION_THROWN|[36]|System.TypeException: Invalid conversion from runtime type Datetime to Date

When I change the input parameter to DateTime it works. What gives?

  • What is being passed as the varStartDate parameter? Can you provide a System.debug call for that parameter? – Renato Oliveira Jul 19 '18 at 18:36
  • @RenatoOliveira the debug looks like this: DEBUG|values:{varStartDate=2018-07-19 07:00:00} so it is being passed from flow to apex as a date time even though the flow is supposed to be setting it as a date :/ – Olivia Jul 19 '18 at 18:38

Well, in Apex, the Date type always has a time component set to zeroes. If you open your developer console and issue a System.debug(Date.today()); you'll get the following:

16:10:46.10 (11087959)|USER_DEBUG|[1]|DEBUG|2018-07-19 00:00:00

Because you get the hours, my guess is that somewhere the platform is passing the Date attribute as a String, and then when you try to read this as a date in Apex, it will get "confused" because of the hours. You can try to cast your Object to a DateTime instead of casting to Date directly.

  • ah that is what I was suspecting. I need to save the value into an object later down in the logic so I am going to have to convert it to a Date. Thank you for your response! – Olivia Jul 19 '18 at 19:23

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.