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
phantom1982phantom1982 

Scope of variable in a Controller class

Can someone please explian the following?

 

Public Class AController{

 

Public AController(){}

 

Private boolean a = false;

 

Public firstupdatea{

this.a = true;

}

 

 

// this is called from the VF page in an action tag.

Public PageReference updatea(){

if (this.a == true){

    // further actions..

    }

}

 

}

 

Can someone please tell if the boolean a will retain the value (set to true) in the firstupdatea() function, when checked in the if condition in updatea()? if not? why and how can to make it work so it retains the value..

 

Thanks

Afzal MohammadAfzal Mohammad

Yes, value will be ratained, if you call firstupdatea() first and then make updatea() call.

 

Hope that helps.

 

Afzal

phantom1982phantom1982

Thanks for replying. The function in the action tag runs after Constructor so the calling flow is ok.. but the value is not being retained.. any idea why??

Ritesh AswaneyRitesh Aswaney

Just wondering how the method is invoked from the  VF Page. If it is invoking {! firstupdatea} (as a getter) , then the method should probably be called

 

Public void getFirstupdatea()

{

this.a = true;

}

 

Not to mention, that sometimes , the order in which Controller methods are invoked are somewhat unpredictable.