Master the concepts of Salesforce in just 45 days Click here to know more.
8
10
58
27
Premium Salesforce Weekend Batch Start From Tomorrow.
To control the flow of code execution apex provides conditional statements and loops which helps us execute the code based on conditions or execute the same code repeatedly for n number of times.
In apex, logic control is divided into 3 parts:
Use the if statement to specify a block of code to be executed if a condition is true.
Syntax:
if (condition)
{
// block of code to be executed if the condition is true
}
Use the else statement to specify a block of code to be executed if the condition is false.
else
// block of code to be executed if the condition is false
Use the else if statement to specify a new condition if the first condition is false.
if (condition1)
// block of code to be executed if condition1 is true
else if (condition2)
// block of code to be executed if condition1 is false and condition2 is true
// block of code to be executed if the condition1 is false and condition2 is false
Shorthand IF
If you have only one statement to execute, one for if, and one for else, you can put it all on the same line:
variable = (condition) ? expressionTrue : expressionFalse;
Loops can execute a block of code as long as a specified condition is reached.
while (condition)
// code block to be executed
do
}while (condition);
for(initialization ; condition ; increment/decrement/operation)
Example:
List<integer> iList = new List<integer>{2,4,6,3,5,8,5,3,5,8,8,5,9};
for(integer a: iList)
for (type variable : arrayname)
a = a*2;
< < Previous
Next > >
The batch is going to start shortly. Fill the form given below to Register yourself now.
Fill out the form and get consulted by our Salesforce experts.
Fill out the form to figure out to detemine the perfect Salesforce profile for yourself.
Fill the form below to get a demo of this course.
Fill out the form to get your Premium Salesforce Development Course
Online Salesforce Development Course is soon going to be launched. Please fill the form and we will notify you about the course.