Activity Forums Salesforce® Discussions What is the scope of static variable in Salesforce Apex?

  • shariq

    Member
    September 22, 2018 at 10:31 pm

    When you declare a method or variable as static, it’s initialized only once when a class is loaded. Static variables aren’t transmitted as part of the view state for a Visualforce page.

    Static variables are only static within the scope of the request. They are not static across the server, or across the entire organization.

  • Parul

    Member
    September 23, 2018 at 3:44 am

    A static local variable is different from a local variable as a static local variable is initialized only once no matter how many times the function in which it resides is called and its value is retained and accessible through many calls to the function in which it is declared, e.g. to be used as a count variable.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos