Here you can see the example of calling the apex class method from anywhere
Sample Apex class
public class student{
public void submit(){
system.debug('This is student class');
}
public static void staticFun(){
System.debug('Hello');
}
}
Non-Static method
create an instance of class then call
student objStudent = new student();
objStudent.submit(); // Output: This is student class
Static Method
You can call simply via class name
student.staticFun(); // Output: Hello
In Salesforce you can execute your test code or sample code in the anonymous window. To open an anonymous window follow these steps:
- Open Developer console after clicking on you name
- In developer console press ctrl+E to open anonymous window
- In an anonymous window, you can execute code whatever you want. In
your scenario, you can create an instance of student class and call
method.
- After writing code click execute in debug log you can see output.
In Lighting, you can open developer console via clicking on gear icon (setting icon).