function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MMuneeeMMuneee 

Why do we write triggers and classes?what is the best one ?

Ravikant Saini 1Ravikant Saini 1
We write trigger to maintain our databse on insert update or delete of any record.

A trigger is Apex code that executes before or after the following types of operations:
insert
update
delete
merge
upsert
undelete
For example, you can have a trigger run before an object's records are inserted into the database, after records have been deleted, or even after a record is restored from the Recycle Bin.
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers.htm
Balaji BondarBalaji Bondar
Hi Muneerndar,

Trigger is the set of custom logic which is executed on DML statement execution(record insert, update or delete).
Classes are the standalone code which consist of custom business logic.Classes can be called from the controller, button action or trigger.

Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
Suraj RaipureSuraj Raipure
Trigger are excecuted quick and are fast. It is activated by certain predefined DML action and help us to implement action upon DML operation. Trigger work in System mode
Classes are just meant for business logic . Class provide us user mode by with sharing.