How to get record id from standard controller using Apex in Salesforce?

How to get record id from standard controller using Apex in Salesforce?

Sample Code:

Visualforce page:<apex:page standardcontroller=”account” extensions=”Sample”>
{!Aid}
</apex:page>

Apex Controller:

public class Sample {

    public Id Aid {get;set;}
   
    public Sample(ApexPages.StandardController controller) {
        Account acc = new Account();
        Aid = controller.getId();
    }        
}

Output in Account Page layout:

Leave a Reply