3

I have this method

    public static string method (Date startDate, Date endDate){
         if(startDate > endDate)
         {
             system.debug(' startDate: '+startDate+' endDate: '+endDate+' today date: '+System.today());
         }

   }

It throws an exception

FATAL_ERROR|System.UnexpectedException: Illegal arguments

The debugging result is

startDate: 2016-2-20 endDate: 2016-2-29 today date: 2016-02-11 00:00:00

Edit:

Start Date field in the component:

<ui:inputDate aura:id="startDate" label="{!$Label.c.Start_Date}" value="{!v.startDate}" displayDatePicker="true"/>
  • Controller is called normally which calls the method in helper

  • Helper:

 var action = component.get("c.method");
            action.setParams({ 
                startDate: component.get("v.startDate"),
                endDate: component.get("v.endDate"),
            });

So Any idea why this exception is thrown?

  • Can you share how your component is calling them ? – Mohith Shrivastava Feb 11 '16 at 12:55
  • I edited the answer to include what you asked for. Thanks – Abdullah Alsaadi Feb 11 '16 at 13:17
2

I just tried debugging this and seems like no issues at all.

Here is the code that worked all good with below code

<aura:component controller="ApexCls">
<aura:attribute name="startDate" type="Date"/>
<ui:inputDate aura:id="startDate" label="tEST" value="{!v.startDate}" displayDatePicker="true"/>
<ui:button press="{!c.checkdate}" label="Find"/>

JS controller

({
checkdate : function(component, event, helper) {
    var action = component.get("c.getmethod");
        var self = this;
        action.setParams({
            startDate: component.get("v.startDate")
        });
        action.setCallback(this, function(response) {
        var state = response.getState();
        console.log('STATE'+response.getReturnValue());
            if (component.isValid() && state === "SUCCESS") {
            }else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    $A.logf("Errors", errors);
                    if (errors[0] && errors[0].message) {
                        $A.error("Error message: " +
                                 errors[0].message);
                    }
                } else {
                    $A.error("Unknown error");
                }
            }
        });
    $A.enqueueAction(action);
   }
 })

The apex class

public class ApexCls {

  @AuraEnabled
  public static void  getmethod (Date startDate){
     system.debug('startDate:'+startDate);
  }

 }
1

Well, I got it working by changing the method signature to receive date as a string then convert it as follows:

public static string method (string dateStart, string dateEnd){
    date startDate = Date.valueOf(dateStart);
}

By the way, the date parameter was being passed correctly but yet we got problems. Receiving it as a string then convert it fixed the problem.

  • check below ..I got it working as below – Mohith Shrivastava Feb 14 '16 at 21:25
  • Are you using design attribute ? – Mohith Shrivastava Feb 14 '16 at 21:25
  • No, I'm not using design attribute. – Abdullah Alsaadi Feb 15 '16 at 20:38
  • I dont think then you need to use string for your conversion .Date works good to me .If you could please post what went wrong and how you solved it ,it will be great help – Mohith Shrivastava Feb 15 '16 at 20:50
  • It is weird but really it did not work till I changed the date passed to string then converted it into Date in Apex method. Have no idea why. – Abdullah Alsaadi Feb 16 '16 at 21:36

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.