Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I'm trying to set a controller property, using apex:param in an actionFunction but the properties aren't being set. This is my actionFunction:

<apex:actionFunction action="{!setStartEndDates}" name="setStartEndDates" rerender="empty_panel">
    <apex:param name="startDate" assignTo="{!StartDateTime}" value=""/>
    <apex:param name="endDate" assignTo="{!EndDateTime}" value=""/>
</apex:actionFunction>

Javascript - start and end are both js moments:

select: function(start, end, jsEvent, view) {
    setStartEndDates(start._d, end._d);
},

And controller:

public String StartDateTime {get; set;}

public String EndDateTime {get; set;}

public PageReference setStartEndDates() {
    CommonLog.debug('start: ' + StartDateTime);
    CommonLog.debug('end: ' + EndDateTime);
    return null;
}

When I log out the date properties, they're both null. I have another actionFunction set up in exactly the same way which is working fine and I can't figure out why this one isn't working. I've tried making the properties DateTime, and passing the full moment object as the param.

share|improve this question
    
Parameters aren't loaded until after the controller finishes initializing, this could be playing a role in your problem. –  Cryst Aug 5 at 15:04

2 Answers 2

up vote 3 down vote accepted

Found out what the problem was and thought I'd post it here in case anyone else has the same issue. Because the start and end were objects (moment), they weren't casting properly to the controller properties. My solution was:

Javascript:

select: function(start, end, jsEvent, view) {
    setStartEndDatesAF(start.format('YYYY-MM-DD HH:mm:ss'), end.format('YYYY-MM-DD HH:mm:ss'));
},

Controller:

public String StartDateTime {get; set;}
public DateTime startDt {get; set;}

public String EndDateTime {get; set;}
public DateTime endDt {get; set;}

public PageReference setStartEndDates() {
    startDt = DateTime.valueOf(StartDateTime);
    endDt = DateTime.valueOf(EndDateTime);
    //FullCalendar selected end is exclusive - deduct 1 second to get inclusive end
    endDt = endDt.addSeconds(-1);
    return null;
}
share|improve this answer

Try to change Salesforce API version of the page and controller to 30.0 instead of 31.0. I ran into the same issue recently and this helped me. Let me know if it works for you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.