What is APEX Programming Language?
Apex is Salesforce’s own programming language. It is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control systems on their cloud-based API(application programming Interface).
APEX is very similar to JAVA and C# but it can only be used in salesforce.
When we save, update or do any other similar work on a record in the Salesforce interface, some apex code is working behind the scenes all the time.
If business wants to implement a scenerai that cannot be used in declarative method.
Apex can be defined used by classes.

Access Modifiers
Private
This access modifier is the default, and means that the method or variable is accessible only within the Apex class in which it is defined. If you do not specify an access modifier, the method or variable is private.
Protected
This means that the method or variable is visible to any inner classes in the defining Apex class, and to the classes that extend the defining Apex class.
Public
Accessible by all Apex within a specific package.
Global
Can be used by any Apex code that has access to the class.
Apex Collections
Lists
A list is an ordered collection of elements that are distinguished by their indices. List elements can be of any data type-primitive types, collections, sObjects, user-defined types, and built-in Apex types.
Sets
A set is an unordered collection of elements that do not contain any duplicates. Set elements can be of any data type-primitive types, collections, sObjects, user-defined types, and built-in Apex types.
Maps
A map is a collection of key-value pairs where each unique key maps to a single value. Keys and values can be any data type-primitive types, collections, sObjects, user-defined types, and built-in Apex types.
Apex Triggers
Triggers are the scripts in apex that get executed either before or after the happening of specific DML events.
Events in Trigger:
- Before
- insert
- update
- delete
- After
- Update
- Insert
- Delete
- Undelete
Before Trigger Vs After Trigger
Before Trigger | Partial Commit
Triggers which are execute before the record is partially committed in database.
Before triggers are used to update or validate record values before they are saved to the database.
After Trigger| Save
Trigger events which are executed after the record is partially committed in database.
After Trigger | Save
Trigger events which are executed after the record is partially committed in database.
After triggers are used to access field values that are set by the system(such as records`s id or LastModifiedDate field), and to effect changes in record.
Apex Trigger Best Practices
- We have to write one trigger per object.
- There is no order in which the triggers will fire, so we can have a single trigger, and, in that trigger, we can control the execution of the apex class methods/processes
- We have to use a trigger framework
- We have to use custom metadata to control the execution of a trigger.
- We have to avoid recursion via a static Boolean flag.