End goal - create a lightning component with a button that calls an Apex Controller method.

The apex controller method is finally being called, but I don't know how to resolve this JS error that is thrown after the Apex method finishes.

Cmp where the controller is defined in line 1:

<aura:component implements="force:appHostable" controller="updateUsingLightningCheckboxController">
    <ui:button label="Activate" press="{!c.onActivate}" aura:id="Activate"/>

JS Controller where the Apex Controller method is called in line 4 successfully:

    onActivate: function(cmp, evt, helper){
        alert("button clicked");
        var action = cmp.get("c.startScheduler");
        alert("cmp gotten?");
        action.setCallback(this, function(data) {
            var state = response.getState();
            if (state === "SUCCESS") {
                alert("From server:" + response.getReturnValue());

Trimmed Apex Controller, where the method works just fine for a VF button but throws the exception for the above lightning component:

public with sharing class updateUsingLightningCheckboxController {
    public static String startScheduler(){
        system.debug('scheduler method started');
        String responseMessage='The app is already scheduled for hourly runs.  Click Deactivate in order to stop the app from updating the custom field: "Using Lightning?"';
        List<CronTrigger> ct=[SELECT Id, NextFireTime FROM CronTrigger WHERE CronExpression =: updateUsingLightningCheckboxUtils.cronJobSchedule];
        if (ct.size()==0){
            } else {
        return responseMessage;
}//Apex Controller

1 Answer 1


You have used data as the callback variable name and hence client side code is failing .

Use data.getState() and data.getReturnvalue() in your code.


You must log in to answer this question.

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