Salesforce-Platform-Developer Practice Test

Salesforce Spring 25 Release
237 Questions

Refer to the following Apex code:

What is the value of x when it is written to the debug log?

B. 1

C. 2

D. 3

C.   2

Explanation:

Let’s break down the code execution step-by-step:

Initialization:

Integer x = 0; // x starts at 0

First Loop Iteration:

x = 1: Assigns x the value 1.

x++: Increments x to 2.

while (x < 1): Checks if 2 < 1 → false → loop exits.

Final Value:

System.debug(x); // Outputs: 2

Salesforce-Platform-Developer Practice-Test - Home Previous
Page 24 out of 237 Pages