Answers for "salesforce apex null check"

0

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;
Posted by: Guest on November-23-2020

Code answers related to "salesforce apex null check"

Browse Popular Code Answers by Language