I have a small Lightning component that calls an Apex function when a button is clicked.

The Apex function queries a list op opportunities and changes their closeDate with the addDays function. When this function is called from my lightning component, it results in a System.UnexpectedException: Illegal arguments.

However, when I call the same function from the Execute Anonymous Window in the developer console there is no problem.

Here is my code:


<aura:component controller="TestComponentController">
    <lightning:button variant="neutral" label="test" onclick="{!c.test}"/>


    test : function test(component, event, helper) 
        "use strict";

        var action = component.get("c.moveDate");

            "days": 6

        action.setCallback(this, function updateSessionCallback(response)
            var state = response.getState();
            if (state === "SUCCESS")
                window.alert("Failed with state: " + state);



public class TestComponentController 
    public static void moveDate(Integer days)
        System.debug('moveDate ' + days);
        List<Opportunity> opportunities = 
            [SELECT Id, CloseDate
             FROM Opportunity];
        for (Opportunity o : opportunities)
            System.debug('from ' + o.CloseDate);
            if (o.CloseDate != null)
                o.CloseDate = o.CloseDate.addDays(days);
            System.debug('to ' + o.CloseDate);
        update opportunities;

And logging (from /aura):

09:52:25:002 USER_DEBUG [6]|DEBUG|moveDate 6
09:52:25:016 USER_DEBUG [12]|DEBUG|from 2017-07-28 00:00:00
09:52:25:017 FATAL_ERROR System.UnexpectedException: Illegal arguments
09:52:25:000 FATAL_ERROR Class.TestComponentController.moveDate: line 14, column 1

Can anyone explain to me what is happening and how I can work around this?

1 Answer 1


Please exchange your line with this piece of code in apex controller.hope it will help you.

o.CloseDate = (o.CloseDate).addDays(Integer.valueOf(days));
  • 2
    Thanks, that did the trick. Though I don't really understand why. As far as I can see days is already an Integer so this should make no difference.
    – H Alves
    Oct 12, 2017 at 9:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .