Posts

Best Practices For Writing a Trigger in Salesforce org

Image
Triggers are very useful automation code based tool to perform easy to complex logic in a Salesforce org. Here are 5 points to keep in mind when writing a trigger. 1) Each object should have only one trigger. 2) Refrain from using SOQL queries or DML statements within FOR loops. 3) Utilize collections for executing DML statements, instead of individual records per statement. 4) Simplify trigger logic by using a trigger handler instead of embedding complex logic directly in triggers. 5) Ensure triggers are "bulkified" to efficiently process up to 200 records in each call. 6) Avoid hardcoding record IDs within the code. 7) Naming convention within the Trigger code should align with the business model.

How to See All Batch Apex Classes in a Salesforce Org?

Image
Running this code in the Developer Console anonymous window will give you the list of all batch apex classes in your Salesforce org. list<ApexClass> lstApexClasses = [SELECT Id, Name, ApiVersion, Body FROM ApexClass where NamespacePrefix = null]; for(ApexClass iterator : lstApexClasses) {     if(iterator.Body.contains('Database.Batchable')) {         system.debug('Batch Class Name ====> '+iterator.Name+' Api Version ====> '+iterator.ApiVersion);     } } After executing the code, open the log and the result will be like