[SalesForce] the difference between System.currentPageReference() and ApexPages.currentPage()

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() vs DateTime.Now() and System.today() versus Date.Today(). It is safe to use either in current code, although one would expect the classic version to be deprecated eventually. Note also that ApexPages.CurrentPage() no longer appears in the documentation, as far as I can tell.

Proof:

Controller

public with sharing class versus {
    public boolean getIsEqual() { return apexpages.currentpage() === system.currentpagereference(); }
}

Page

<apex:page controller="versus">
    {!isEqual}
</apex:page>

Output

true

Conclusion

Since === compares two memory locations, and this operator returning true means that both functions are literally returning the same value.

Related Topic