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
Ritu Ghosh 5Ritu Ghosh 5 

In which case do we use ApexPages.currentPage() and when do we use System.currentPageReference()?

NagendraNagendra (Salesforce Developers) 
Hi Ritu,

There is no difference - both System.currentPageReference() and ApexPages.currentPage() return a reference to the current page.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 the 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(); }
}
Visual Force 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.

Hope this helps.

Please mark this as solved if it;s resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra

 
Ritu Ghosh 5Ritu Ghosh 5
Thanks for sharing this information.