function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Daniel Watson 21Daniel Watson 21 

Running Scheduled Jobs [Off Hand]

I have several Schedulable Apex classes that run monthly to build out some custom objects and cases for coming projects in coming months. There may however be instances where my company adds an account and need to run these jobs manually to quickly get the account on track, rather than waiting until the first of the next month for my jobs to do so.

I slapped together a lighting page component with some buttons that call to the controller methods that create an instance of the schedulable class and then calls:
[instance].execute(null);
When I click on the component buttons, sometimes I get a recursion error. Logging "response" to the console, I get like 1000 "SUCCESS" objects, but no new objects / cases are created in the database. I am concerned that this is just not how these classes should be called.

Is there a better way to accomplish what I am describing?

Thanks!

CODE:
MARKUP:
<aura:component controller="Controller_RunApex" implements="flexipage:availableForAllPageTypes" access="global">
    <lightning:card title="ApexRunner" class="container">
        <lightning:button variant="brand" label="ReconciliationsForAccounts" onclick="{!c.ReconciliationsForAccounts}" />
        <lightning:button variant="brand" label="CasesForReconciliations" onclick="{!c.CasesForReconciliations}" />
        <lightning:button variant="brand" label="CustomCasesMonthly 1st" onclick="{!c.CustomCasesMonthly}" />
        <lightning:button variant="brand" label="CustomCasesWeekly Fri" onclick="{!c.CustomCasesWeekly}" />
    </lightning:card>
</aura:component>
CONTROLLER:
({
    ReconciliationsForAccounts : function(component, event, helper) {
        helper.runFunction(component, helper, "c.ReconciliationsForAccounts");
    },
    
    CasesForReconciliations : function(component, event, helper) {
        helper.runFunction(component, helper, "c.CasesForReconciliations");
    },
    
    CustomCasesMonthly : function(component, event, helper) {
        helper.runFunction(component, helper, "c.CustomCasesMonthly");
    },
    
    CustomCasesWeekly : function(component, event, helper) {
        helper.runFunction(component, helper, "c.CustomCasesWeekly");
    }
})
HELPER:
({
    runFunction : function(component, helper, functionName) {
        var action = component.get(functionName);
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                console.log(response);
            }
            else {
                helper.consolelLogErrors(response.getError());
            }
        });
        $A.enqueueAction(action);
    },
    
    /**
     * Logs errors to the browser console log.
     * @param {String} errors: The errors to display.
     */
       consolelLogErrors : function(errors) {
        if (errors) {
            if (errors[0] && errors[0].message) {
                console.log("Error message: " + errors[0].message);
            }
        } else {
            console.log("Unknown error");
        }
    }
})
APEX:
public class Controller_RunApex {
    
    @AuraEnabled
    public static void ReconciliationsForAccounts() {
        Schedulable_ReconciliationsForAccounts rfa = new Schedulable_ReconciliationsForAccounts();
        rfa.execute(null);
    }
    
    @AuraEnabled
    public static void CasesForReconciliations() {
        Schedulable_CasesForReconciliations cfr = new Schedulable_CasesForReconciliations();
        cfr.execute(null);
    }
    
    @AuraEnabled
    public static void CustomCasesMonthly() {
        Schedulable_CustomCasesMonthly_1st ccm1 = new Schedulable_CustomCasesMonthly_1st();
        ccm1.execute(null);
    }
    
    @AuraEnabled
    public static void CustomCasesWeekly() {
        Schedulable_CustomCasesWeekly_Fri ccwf = new Schedulable_CustomCasesWeekly_Fri();
        ccwf.execute(null);
    }
}
All my schedulable classes are @ 100% coverage and are bulk-ifide. Can post their code as well on request.

THANKS ALL!