What is apex :-
Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Lightning Platform server, in conjunction with calls to the API. Apex is like Java for Salesforce. It uses classes, data types, variables, and if-else statements.
Uses of Apex class :-
- In Salesforce, Apex classes are used to implement the actions associated with an object.
- Apex classes will have specific methods to execute the actions of the object.
- classes will have constructors to create the objects.
When Should I Use Apex :-
The Salesforce prebuilt applications provide powerful CRM functionality. In addition, Salesforce provides the ability to customize the prebuilt applications to fit your organization.
However, your organization may have complex business processes that are unsupported by the existing functionality.
In this case, Lightning Platform provides various ways for advanced administrators and developers to build custom functionality.
We can use Apex when we want to −
- Create Web services with integrating other systems.
- Create email services for email blast or email setup.
- Perform complex validation over multiple objects at the same time and also custom validation implementation.
- Create complex business processes that are not supported by existing workflow functionality or flows.
- Create custom transactional logic (logic that occurs over the entire transaction, not just with a single record or object) like using the Database methods for updating the records.
- Perform some logic when a record is modified or modify the related object’s record when there is some event which has caused the trigger to fire.
How Does Apex Work :-
All Apex runs entirely on-demand on the Lightning Platform. Developers write and save Apex code to the platform, and end users trigger the execution of the Apex code via the user interface.
Apex is compiled, stored, and run entirely on the Lightning Platform:
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.