salesforce apex null check
// Existing lengthy code checking for null fields
results = [SELECT Name FROM Account WHERE Id = :accId];
if (results.size() == 0) { // Account doesn't exist, isn't visible, was deleted, etc
return null;
}
return results[0].Name;
// New crisp code using the safe navigation operator
return [SELECT Name FROM Account WHERE Id = :accId]?.Name;