1

End goal - have a doneRendering event which calls an Apex method to determine if a scheduled job exists or not.

I have an apex controller method that I've verified works in execute anonymous in the dev console. I've verified that every line up until this one in my helper method works:

        var action = cmp.get("c.isSchedulerActivated");

I've triple checked syntax and everything lines up with other controller methods fired from click events, so the only thing I can think is that doneRendering might be firing the event before I can target the apex controller method?

Component:

<aura:component implements="force:appHostable" controller="updateUsingLightningCheckboxController">
<aura:handler event="aura:doneRendering" action="{!c.doneRendering}"/>
<aura:attribute name="isDoneRendering" type="Boolean" default="false"/>
<aura:attribute name="isAppActive" type="Boolean" default="false"/>
</aura:component>

Controller:

({

doneRendering: function(cmp, evt, helper) {
    if(cmp.get("v.isDoneRendering") === false){
        cmp.set("v.isDoneRendering", true);
        console.log("Is done rendering set to true? "+ cmp.get("v.isDoneRendering"));
        helper.isActivated();
        console.log("isActivated is done"); //this does not fire
    }//if
} })

Helper:

({
isActivated: function(cmp) {
    console.log("Helper method entered");
    var action = cmp.get("c.isSchedulerActivated"); //THIS IS THE LINE THAT RESULTS IN ERROR THROWN

    action.setCallback(this, function(response) {
        var state = response.getState();
        console.log("result of isSchedulerActivated is:  "+ response.getReturnValue());
        if (state === "SUCCESS") {
            console.log("state === success  ");
        }//if
    });
    $A.enqueueAction(action);
} })

Apex Controller:

public with sharing class updateUsingLightningCheckboxController {

@AuraEnabled
public static Boolean isSchedulerActivated(){
    Boolean isActivated=FALSE;
    CronTrigger[] cts= [SELECT Id, NextFireTime, State FROM CronTrigger WHERE CronExpression =: updateUsingLightningCheckboxUtils.cronJobSchedule];
    if (cts.size()>0)
        isActivated=TRUE;
    return isActivated;
}//isSchedulerActivated }//updateUsingLightningCheckboxController

I'm struggling to figure this out, and this is the last thing I need to resolve before publishing an app that creates a Lightning Adoption Dashboard so any help is greatly appreciated!!

1 Answer 1

2

I would use init event instead of done rendering event and use setTimeout() to continuously poll to check the scheduled status .

Also try passing the cmp to the helper

helper.isActivated(cmp)

Here is an example of how to poll http://www.jitendrazaa.com/blog/salesforce/calling-apex-method-at-regular-interval-from-lightning-component/#more-5715

2
  • I don't understand what I would poll for - response.getState()? If I comment out everything except the var action = cmp.get("c.isSchedulerActivated"); I still get the error so I was assuming it was something around that var definition that threw the error, not the callback. Thanks for the reply! Commented Dec 6, 2016 at 5:10
  • You are missing variable passing to helper. Check the updated and but always use init handler instead of done rendering Commented Dec 6, 2016 at 5:14

You must log in to answer this question.

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