The Execute Anonymous Apex tool in the Developer Console runs the Apex code you enter using ExecuteAnonymousand generates a debug log with the results of the execution.
public class myControllerExtension {
private final Account acct;
// The extension constructor initializes the private member
// variable acct by using the getRecord method from the standard
// controller.
public myControllerExtension(ApexPages.StandardController stdController) {
this.acct = (Account)stdController.getRecord();
}
public String getGreeting() {
return 'Hello ' + acct.name + ' (' + acct.id + ')';
}
}
You can execute the Execute Anonymous Apex tool in the Developer Console as shown below
Account acc= new Account();
acc.Name='test' ;
insert acc ;
ApexPages.StandardController stdAcc = new ApexPages.StandardController(acc);
myControllerExtension extes=new myControllerExtension(stdAcc);
extes.getGreeting();
Naveen
The Execute Anonymous Apex tool in the Developer Console runs the Apex code you enter using ExecuteAnonymousand generates a debug log with the results of the execution.
Refer this link
https://help.salesforce.com/articleView?id=code_dev_console_execute_anonymous.htm&type=5
Lets support this is your class
You can execute the Execute Anonymous Apex tool in the Developer Console as shown below
From Vf page like below ..