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
HChauhanHChauhan 

Help with Setter and Getter Method

New to salesforce development. Primarily a dot net developer.

In two or more properties of my controller I want to access values from another controller's properties.

This is how my controller is looking -

 

Controller1 POutlook = new Controller1();

 

 public Decimal currentMonthActualPer {
       get
        {
          return Controller1.currentMonthActualPer;
        }
    }
     public Decimal currentMonthForecastPer {
       get
        {
          return Controller1.currentMonthForecastPer;
        }
    }
    Public String currentMonthBackground{
       get
        {
          return Controller1.currentMonthBackground;
        }
    }
  

 

In my visualfocepage I am accesing this properties directly as -

 

{!currentMonthActualPer} and {!currentMonthForecastPer}

 

Now, I am not sure about Page life cycle of Apex page just wanted to confirm that Apex engine will execute statement -

Controller1 POutlook = new Controller1(); only once or will it call it every time a property's is called(Binded) in visualforce page.

Lot of calculation code has been written Controller1 constructer so just want to execute it once only.

 

RavitejaRaviteja
Try POutlook instead of Controller1
Ex::return POutlook.currentMonthActualPer;
HChauhanHChauhan

Thanks srirama10, But that is a typo error my question is different -

 

 just wanted to confirm that Apex engine will execute statement -

Controller1 POutlook = new Controller1(); only once or will it initialize object every time a property's is called(Binded) in visualforce page.

 

New to salesforce development. Primarily a dot net developer.

In two or more properties of my controller I want to access values from another controller's properties.

This is how my controller is looking -

 

Controller1 POutlook = new Controller1();

 

 public Decimal currentMonthActualPer {
       get
        {
          return POutlook.currentMonthActualPer;
        }
    }
     public Decimal currentMonthForecastPer {
       get
        {
          return POutlook.currentMonthForecastPer;
        }
    }
    Public String currentMonthBackground{
       get
        {
          return POutlook.currentMonthBackground;
        }
    }
  

 

In my visualfocepage I am accesing this properties directly as -

 

{!currentMonthActualPer} and {!currentMonthForecastPer}

 

Now, I am not sure about Page life cycle of Apex page just wanted to confirm that Apex engine will execute statement -

Controller1 POutlook = new Controller1(); only once or will it call it every time a property's is called(Binded) in visualforce page.

Lot of calculation code has been written Controller1 constructer so just want to execute it once only.

Prafull G.Prafull G.
Hello HChauhan,

The visualforce page lifecycle is similar to .net pages. First the constructor will execute and it will be once on a page load.
Also, have a look at the following documentation for more info
http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_lifecycle.htm

Let me know if you want more details around this.

With Best,
Prafull