Is there any way to assign value to global variable in salesforce helper javascript?


    resetTime: 30000,
    refreshNotif: function(component, helper) {

                $A.getCallback(function() {
                    console.log('test 1');

 updateRead: function(component, helper) {
        helper.resetTime = 50000;


my question is, when page loads the refreshNotif function is getting called and the reset time value should be 30000. but when updateRead function is called how can i assign the value 50000 to resetTime global variable so that helper.resetTime in the refreshNotif function should also get updated to 50000.

is my approach above is correct?

Right now the value is set to 30000 even when the second function getting called


Use Aura attribute to store the resetTime value, you can easily access that from the helper.

<aura:attribute name="resetTime" type="Integer" default="30000"/>

set that from helper

updateRead: function(component, helper) {
    component.set("v.resetTime", 50000);

get it like this,

let time = component.get("v.resetTime");
  • 1
    it worked. thanks
    – Arzad
    Mar 19 '20 at 15:35
  • @Arzad Most welcome! Mar 19 '20 at 15:44
  • is there a way to declare global variable without initializing a value in JS controller in salesforce? Ex: resetTime: , refreshNotif: function(component, helper) { // } assigning values to global variable dynamically?
    – Arzad
    Mar 20 '20 at 5:00
  • @Arzad you can set it to undefined, but I doubt if you can change that value later. In my personal opinion it is always better to use aura:attribute. Mar 20 '20 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.