I have written a helper class that I will be using throughout my Aura app. I have created a static resource file where I have added my auraUtils.js file.

In one of my components I am doing a doInit() call to retrieve data via an Apex class.

For everyone's benefit I am pasting my helper class below.

I am getting an undefined (auraUtils is undefined) message because (I presume) the component for doInit is not yet initialised. I have however placed my ltng:require ...auraUtils.js file into the app and other parent components.

Does anybody know of an elegant way of achieving this global helper class without having to paste the snippet into every component helper class?

Any help would be much appreciated as I am new to lightning.

var auraUtils = auraUtils || {}; 
auraUtils.getCompletedJobs = function(cmp, successCB, errorCB){
    auraUtils._createApexAuraCall(cmp, 'c.getCompletedJobs', null, successCB, errorCB);

auraUtils.getJobsByType = function(cmp, paramsMap, successCB, errorCB){
    auraUtils._createApexAuraCall(cmp, 'c.getJobsByType', paramsMap, successCB, errorCB);
auraUtils.getInProgressJobsByType = function(cmp, paramsMap, successCB, errorCB){
    auraUtils._createApexAuraCall(cmp, 'c.getInProgressJobsByType', paramsMap, successCB, errorCB);

// Private Methods
auraUtils._createApexAuraCall = function(cmp, name, paramsMap, successCB, errorCB){
    var a = cmp.get(name);
    if(paramsMap && paramsMap!=null){
    if(!cmp || !cmp.isValid()){
        console.error('Component variable was not valid', cmp);
        return false;
    a.setCallback(this, function(response) {
        var state = response.getState();
        if (state === 'SUCCESS') {
        else if (state === 'INCOMPLETE') {
            alert("The server did not return a response. The server might be down or the client might be offline.");
        else if (state === 'ERROR') {
            var errors = response.getError();
            if (errors) {
                if (errors[0] && errors[0].message) {
                    console.error("Error message: " + errors[0].message);
            } else {
                console.error("Unknown error");

1 Answer 1


you can make the JS file a static resource and invoke the file on load of your component


 <ltng:require scripts="{!$Resource.auraJSUtil}"/>


    myMethod : function(cmp, event, helper){
        getCompletedJobs(cmp, event, helper)


You might have to refactor the JS methods to use base JS instead of the lightning version of method instantiation


getCompletedJobs = function(cmp, event, helper) {
    //your code here

You must log in to answer this question.