In my apex controller how can I find out what my current page name is? I have need where I am redirecting from one page to another. My first page does not have any parameters but my 2nd page has a parameter. I am using the same controller for both the pages. So when I try to get the parameter name(part of page2) in constructor when page1 is loaded I get a null pointer exception because there is no parameter for page1

I tried this but does not seem to work. Here page2 has a parameter called param1 and Page1 has no parameters. When the page1 is loaded first it goes to else condition and throws a null pointer exception when I try to get that parameter:

if(ApexPages.currentPage() == Page.page1){
// do nothing

objectName = ApexPages.currentPage().getParameters().get('param1');

Any Suggestions?

1 Answer 1


You can parse the URL to get the name of the current page.

String pageName = ApexPages.currentPage().getUrl()
  • Bravo! Just what I wanted:)
    – SfdcBat
    Commented Dec 9, 2016 at 23:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .