Material 07
Material 07
Important Considerations:
Governor Limits: Be mindful of limits on SOQL queries, DML operations,
and CPU time. Exceeding these limits will result in runtime exceptions.
Bulkification: Ensure that code is bulkified to handle multiple records in a
single transaction.
Transaction Control: Manage transaction boundaries carefully to ensure
data integrity.
3. Handling Transactions and Governor Limits
Transactions in Synchronous Apex:
Single Transaction: All operations within a synchronous Apex method are
part of a single transaction.
Atomicity: If any part of the transaction fails, the entire transaction is rolled
back.
Commit: The transaction is committed only if all operations succeed without
errors.
Governor Limits:
CPU Time: Limited to 10,000 milliseconds for synchronous operations.
SOQL Queries: Limited to 100 SOQL queries per transaction.
DML Statements: Limited to 150 DML statements per transaction.
Heap Size: Limited to 6 MB for synchronous transactions.
Best Practices to Handle Limits:
Bulkification: Write code that can handle multiple records efficiently to
avoid hitting limits.
Efficient Queries: Optimize SOQL queries to return only the necessary data.
Use Limits Class: Use the Limits class to monitor and debug governor
limits.
Thank You