I couldn't find this properly defined anywhere in docs on when to use System class and when to use ApexPages class to fetch current page reference. Does anyone know if there is actually any difference in using it in different situations?
I couldn't find this properly defined anywhere in docs on when to use System class and when to use ApexPages class to fetch current page reference. Does anyone know if there is actually any difference in using it in different situations?
Best Answer
The two are synonymous. The former is the classic means of accessing the current page, while the new method was introduced as a part of the recent normalization of functions. Other functions have also been duplicated in more appropriate spaces, such as
System.Now()
vsDateTime.Now()
andSystem.today()
versusDate.Today()
. It is safe to use either in current code, although one would expect the classic version to be deprecated eventually. Note also thatApexPages.CurrentPage()
no longer appears in the documentation, as far as I can tell.Proof:
Controller
Page
Output
Conclusion
Since
===
compares two memory locations, and this operator returning true means that both functions are literally returning the same value.