SIGN IN SIGN UP

Login to your account

Username or Email *
Password *
Remember Me
Apex Intermediate Progress | ( Lessons)
%

Lesson: 05 | Null Check


In Apex, which is the programming language used by Salesforce for building custom applications on the Salesforce platform, a null check is a common practice to ensure that a variable or an object reference is not null before attempting to access its properties or methods. Performing a null check helps prevent null pointer exceptions, which can occur when trying to perform operations on a null object.

Here's a basic example of a null check in Apex:

String StringA = 'Hello, Salesforce!';
String StringB = null;

if (StringA != null) {
    System.debug('StringA is not NULL. The length of StringA is ' + StringA.length());
} else {
    System.debug('StringA is null');
}

if (StringB != null) {
    System.debug('StringB is not NULL. The length of StringB is ' + StringB.length());
} else {
    System.debug('StringB is null');
}

 


You need to login to have access to the quizzes.

Mastered by 13 users.

Apex Intermediate

A. Apex DML Operations (8 lessons)
B. Apex Classes (17 lessons)
C. Apex Triggers (9 lessons)
D. Apex Exceptions (11 lessons)
E. Asynchronous Apex (6 lessons)
F. SOSL (10 lessons)
G. Testing Apex (9 lessons)
H. Apex Fast Recap (142 lessons)
I. Build Apex Coding Skills (64 lessons)
Go to top