get current record id salesforce

May times we require the current record id in controller. For example if you have a button on detail page overridden by visualforce page and once the button is pressed you require the id(or the other field values of that record) of the record from whose detail page the button was clicked. For this we can use ApexPages.CurrentPage().getparameters().get('id').
In the following example the custom button on account(overridden with following vf page) when clicked shows you the id of the record in visualforc apge.
Visualforce Page

If you want to get any other fields from that record you will have to query that record using the retrieved id as shown in the below example where some of the account fields are displayed.
Visualforce page

We can also get the current record id/record from the standardcontroller methods getid(), getrecord() as shown in the example below:
getRecord() returns the record but to access the fields of that record; those fields should be referenced in the associated Visualforce markup or should be queried before showing in page.


  1. Great work with much info..Go ahead...

  2. The controller, vf page, examples are missing. Has it been removed intentionally?