+ Start a Discussion
jaanvivekjaanvivek 

what is the usage of apexpages.currentpage.getparameter().get('id')

Could you please explain about the usage of apexpages.currentpage.getparameter().get('id'). with an example.

 

1- in which situations we need to use this..

 

 

 

Thanks,

JaanVivek

 

 

 

 

Ankit AroraAnkit Arora

This is to get the parameter value passed in URL, like my URL is this:

 

https://na9.salesforce.com/apex/MyTestPage?id='a01E000000ByPso'

 

Now using "apexpages.currentpage.getparameter().get('id')" in apex I can get the value "a01E000000ByPso"

 

For more reference please visit:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_pages_pagereference.htm

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

sfdcfoxsfdcfox

As a small addendum, it should be noted that "ApexPages.CurrentPage.getParameter().get('Id')" is rarely needed when the page is an "extension", as this parameter is automatically passed to your extension via the ApexPages.StandardController parameter of the constructor:

 

private Id recordId;

public MyExtension(ApexPages.StandardController controller) {
  recordId = controller.getId();
}

I've noticed a trend amongst novice developers to ignore the ApexPages.StandardController parameter, probably because they do not understand its intended use, which leads to code bloat and less maintainable code (e.g. if your logic changes and you need to load a different record ID, it can become non-trivial to determine where this ID value is used).