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
Sushma PriyaSushma Priya 

Before writing a Trigger...

Hi,

 

Please let me know what all things we need to take care while writing a Trigger,

 

  1. How to decide before or after trigger to use
  2. What all configurations we need to go through
  3. Batch size 
  4. How to bulkify a Trigger
  5. How to avoid hitting Governor Limits
  6. Loops, and any other best practices to implement

 Apart from above points, please include other points if I missed out any.

 

Thanks,

Sush.

steve456steve456

1)before or after ttrigger depends on the context .If the trigger needs to fire on the same object use before if its on an other object use after.

 

2)Configurations---There is nothing much

 

3)It dependds on number of records you want to retrieve

 

4) 5) 6)

 

Use collections and SOQL

 

and also make sure u donot write any SOQL s in for loops

 

 

You should be good

Shreya...Shreya...

While developing in Apex, one of the most important things to remember when designing your classes and triggers is always to code for bulk operations. Apex governor limits can be very problematic when your code doesn’t properly handle processing multiple records in the same transaction. Here are some tips for ensuring your code is ready for collections of data in the same transaction. Always perform your queries and DML statements on collections, instead of individual records. This is because Apex governor limits control how may queries and DML statements are allowed per transaction. Performing these operations on collections minimizes the amount of times you have to make a query or perform a DML operation.