@Pradipta Sen, Thanks for your writing. Here I only consider some Best Practices around Governor Limits, we can maintain those bellow Practices to keep SFDC GL (Governor limits) in mind:
Trigger :
§ Always optimize. Even if you think it is not needed, as your trigger can be run from another trigger, which can reach governor limits.
§ Beware of over optimization side effects; when optimizing SOQL queries and DMLs, you will probably use structured maps indexed by IDs. This consumes a lot in memory as triggers are limited in heap size and each trigger in the transaction can consume much heap. Free memory if such structures are not needed after usage.
§ Don't push "trigger.new" to the handler class method, you should filter on records that are in related scope. You will increase performance, reduce governor limits consumption, and limit regression risks when updating the class.
SOQL:
§ Limit returned records. If a query is returning multiple records, you must add "limit xxx" at the end of the query to manage governor limits
DML:
§ · Dirty check of record is very important. In your Apex code, before performing any update DML, check if data is even changed or not? Code in Maximum time, where DML is done on record but it already has same value in Database. We need to issue one extra SOQL and compare. It will save CPU time as well DML governor limit. Its huge game changing approach in Large Data Volume orgs.
@Pradipta Sen, Thanks for your writing. Here I only consider some Best Practices around Governor Limits, we can maintain those bellow Practices to keep SFDC GL (Governor limits) in mind:
Trigger :
§ Always optimize. Even if you think it is not needed, as your trigger can be run from another trigger, which can reach governor limits.
§ Beware of over optimization side effects; when optimizing SOQL queries and DMLs, you will probably use structured maps indexed by IDs. This consumes a lot in memory as triggers are limited in heap size and each trigger in the transaction can consume much heap. Free memory if such structures are not needed after usage.
§ Don't push "trigger.new" to the handler class method, you should filter on records that are in related scope. You will increase performance, reduce governor limits consumption, and limit regression risks when updating the class.
SOQL:
§ Limit returned records. If a query is returning multiple records, you must add "limit xxx" at the end of the query to manage governor limits
DML:
§ · Dirty check of record is very important. In your Apex code, before performing any update DML, check if data is even changed or not? Code in Maximum time, where DML is done on record but it already has same value in Database. We need to issue one extra SOQL and compare. It will save CPU time as well DML governor limit. Its huge game changing approach in Large Data Volume orgs.
NOTE: Enable Apex Governor Limit Warning Emails by Enable "Send Apex Warning Emails option."
More Information regarding SFDC Best Practice, Please read my blog post :
https://www.sfdconcept.com/post/salesforce-best-practice-part-1