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
JayNicJayNic 

Submitting a date through an Action Function - VF Error "cannot be converted from Text to DateTime"

Hi Guys,

 

I'm trying to use an action function to submit parameters to an instantiated sObject.

 

My action function looks like so:

    <apex:actionFunction action="{!updateCredential}" name="af_updateCredential" reRender="none" >
        <apex:param assignTo="{!credential.LastClicked__c}" name="LastClicked__c" value=""/>

    </apex:actionFunction>

<script>

function setClicked(){
    
    var d = new Date();
    var year = d.getFullYear();
    var month = d.getMonth();
    var day = d.getDate();
    var hour = d.getHours();
    var minute = d.getMinutes();
    
    if(month.toString().length == 1) {
        month = '0' + month;
    }
    if(day.toString().length == 1) {
        day = '0' + day;
    }
    if(hour.toString().length == 1) {
        hour = '0' + hour;
    }
    if(minute.toString().length == 1) {
        minute = '0' + minute;
    }
    
    var dt = year + '-' + month + '-' + day + 'T' + hour + ':' + minute +  ':00Z';
    //dt = 'Thu Nov 15 22:29:00 GMT 2012';
    af_updateCredential(dt);
}

</script>

 Where Credential is an sObject with a DateTime field called LastClicked__c.

As you can see, I attempted to format the date/time string to what Apex likes, but I still end up getting an error like so:

--------------------------

Visualforce Error
 

Value '2013-05-19T13:32:00Z' cannot be converted from Text to DateTime

Error is in expression '{!credential.LastClicked__c}' in page credentialsbrowser
--------------------------
 
I really really really don't want to have to write an apex date/time parser JUST for this one silly field, I feel like I should be able to submit it to text with the right formatting.
 
Any help?
Best Answer chosen by Admin (Salesforce Developers) 
Puja_mfsiPuja_mfsi

HI,

In Param the value attribute must be set to a string, number, or boolean value not date ,dateTime etc.

I know the error is different but you can't pass date or dateTIme values from param .You need to send String value after that convert  this value to dateTime in apex .

 

Please visit the URL:

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_param.htm

 

 

If this post helps you please throw Kudos by click on start at left.

All Answers

Puja_mfsiPuja_mfsi

HI,

In Param the value attribute must be set to a string, number, or boolean value not date ,dateTime etc.

I know the error is different but you can't pass date or dateTIme values from param .You need to send String value after that convert  this value to dateTime in apex .

 

Please visit the URL:

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_param.htm

 

 

If this post helps you please throw Kudos by click on start at left.

This was selected as the best answer
Yoganand GadekarYoganand Gadekar

You need to make sure the two data types are of similarb type,

 

You can browse thruogh this example to know more about actionfunction,

http://cloudforce4u.blogspot.in/2013/06/actionfunction-in-apex.html

 

thanks,

JayNicJayNic
Thanks
Despite that the answer sucks, it IS the answer.

Silly Salesforce... I'm sure building more chatter crap is more important that basic data casting.