What is a Apex
Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Force.com platform. It's syntax looks like Java and acts like database stored procedures, Apex enables developers to add business logic to most system events, including button clicks, related record updates, and Visualforce pages.
What is going in Apex:
All Apex runs entirely on-demand on the Force.com platform.and It's compiled, stored, and runs entirely on the Force.com platform. See the pic below how does apex works.
- When a developer writes and saves Apex code to the platform, the platform application server first compiles the code into an abstract set of instructions that can be understood by the Apex runtime interpreter, and then saves those instructions as metadata.
- When an end-user triggers the execution of Apex, perhaps by clicking a button or accessing a Visualforce page, the platform application server retrieves the compiled instructions from the metadata and sends them through the runtime interpreter before returning the result. The end-user observes no differences in execution time from standard platform requests.
When Should We Use Apex:
- To create a email Services
- Perform complex validations multiple Objects
- To create complex business logics that are not supported by salesforce customization.
- Create web services.