Skip to main content


Showing posts from August, 2012

Avoid hitting governor limits

DML operation Using DML statement inside the for loop is not a good practise.Total number of DML operation can be performed in a Apex class is 150. The following example doesn't bulkify DML operation, it will throw an Apex governor limit exception. In this example for loop iterates over LineItem contained in the liList list variable, for each iteration it will update Line item with new description. It will work up to 150 recrds, for the 151st records this trigger throws an run time exception for exceeding governor limit for DML operation. So how can we over come this issue? one straight answer is avoid DML operation inside the for loop Below example is recommended alternative code which will work in Bulk operation More efficient SOQL Queries Similar to DML operation placing the SOQL query inside the loop is not a good practise. Total number of SOQL query issued in the apex class is 100. The following example shows the inefficient querieng of child item. The SOQL quer