When to use Apex?
- To perform a couple of business processes that are not supported by workflows or processes or salesforce flows.
- To perform complex validations on multiple objects.
- To create web services and email services.
- For transactions and rollbacks.
Flows of Action or Client Server Architecture
1. Developer Action
When the developer writes and saves the code to the apex platform. The platform application server compiles the code into a set of instructions that can be understood by the apex runtime, interprets, and then saves those instructions as compiled apex.
2. End-User Action
When the end-user performs some action that involves the apex code or when the end-user triggers the execution of the Apex by clicking a button or accessing a VF page or interacting with the lightning component. The platform application server retrieves the compiled instructions from the meta-data and sends it through apex runtime which interprets before returning the result. The end-user observes no differences in the execution time as compared to the standard application platform request.