Write Efficient Apex and SOQL

To improve the overall performance of a Visualforce page, write efficient Apex and SOQL.

When you write Apex or SOQL for use within a Visualforce page:

  • Perform calculations in SOQL instead of in Apex whenever possible.
  • Never perform Data Manipulation Language (DML) operations inside a loop.
  • Filter in SOQL first, then in Apex, and finally in Visualforce.