Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Salesforce platform server in conjunction with calls to the API. It has a Java-like syntax and acts like database stored procedures.
Apex Anti-Patterns Overview
SOQL Queries Inside Loops
DML Operations Inside Loops
Not Bulkifying Triggers
Hardcoding Record IDs
Not Using the Limits Class
Not Using Try-Catch Blocks
Using System.debug for Production Logging
Not Using Test.startTest() and Test.stopTest()
Not Using @TestVisible
Not Using SObjectType for Field and Object Access
Not Using WITH SECURITY_ENFORCED
Not Using Proper Sharing Settings
with sharing
, without sharing
, or inherited sharing
. The with sharing
keyword enforces record-level security, while without sharing
bypasses it. Use without sharing
only when absolutely necessary, and document why it’s needed.Not Using Proper Trigger Frameworks
Not Using Proper Naming Conventions
Not Using Asynchronous Apex When Appropriate