The actual order depends on what markup is in the page. setCon
's get
(the getter method) could be called multiple times, and could be called in any order relative to getOpportunities
. getOpportunities
itself could also be called multiple times. The only thing we know for sure from this code is that getOpportunities
will automatically call setCon
's get
method to initialize the variable if it hasn't already been initialized.
The approximate order of execution is as follows:
public class opportunityList2Con {
public ApexPages.StandardSetController setCon {
// Step 3: The getter is called
get {
// Step 4: The variable is currently null, so...
if(setCon == null) {
// Step 7: The StandardSetController is assigned to the variable
setCon =
// Step 6: The constructor is called with a QueryLocator
// At this point, the 10,000 row limit is checked, exception thrown if exceeded
// Internal state of StandardSetController is initialized
new ApexPages.StandardSetController(
// Step 5: A QueryLocator is initialized with the inline query
// Note, this is special "magic", the query is not yet fully executed.
Database.getQueryLocator(
[SELECT Name, CloseDate FROM Opportunity]
)
);
}
// Step 8: the value is returned to the caller
return setCon;
}
// Never used in this code
set;
}
// Step 1: {!opportunities} is in the markup
public List<Opportunity> getOpportunities() {
// Step 10: The list is returned to the page
return
// Step 9: The list is cast from sObject[] to Opportunity[]
(List<Opportunity>)
// Step 2: The variable sees .getRecords(), so it must call getter
setCon
// Step 8: The method is called on the value returned from the getter
.getRecords();
}
}
Note that if other expressions are in play, such as {!setCon.hasNext}
, this order may be different, and may even be randomly evaluated on each page load. The system makes no guarantee about the order in which getters are called with regards to expressions that are in the Visualforce markup.