Table of Contents
Introduction
A combination of one or more operands is known as Expressions and we can create compound expressions by joining the expressions to one another with operators.
Expression Operators In Salesforce
We have multiple expression operators mentioned below:
Operator | Syntax | Name | Description | Example |
---|---|---|---|---|
= | a = b | Assignment Operator | assigns the value of b to a. | Integer a = 5 Integer b = 2 a = 2 |
+= | a += b | Addition Assignment Operator | Corresponds to a = a + b. Addition of a and b value assigns to a. | Integer a = 5 Integer b = 2 a = a + b a = 5 + 2 a = 7 |
-= | a -= b | Subtraction Assignment Operator | Corresponds to a = a – b. Value from subtraction of a and b assigns to a. | Integer a = 5 Integer b = 2 a = a – b a = 5 -2 a = 3 |
*= | a *= b | Multiplication Assignment Operator | Corresponds to a = a * b. Value from multiplication of a and b assigns to the a. | Integer a = 5 Integer b = 2 a = a * b a = 5 *2 a = 10 |
/= | a /= b | Division Assignment Operator | Corresponds to a = a / b. Value from Division of a and b assigns to the a. | Integer a = 8 Integer b = 2 a = a / b a = 8 / 2 a = 4 |
&& | a && b | AND Logical Operator | Right associative. If a and b have Boolean data type and both are true, then a would be true. Otherwise a would be false. | Boolean a = true Boolean b = false, true && false //false |
|| | a || b | OR Logical Operator | If a and b have Boolean data type and both are false, then a would be false. Otherwise, a would be true. | Boolean a = true Boolean b = false, true || false //true |
== | a == b | Equality Operator | It returns Boolean after comparison. True if a and b are equal. Otherwise false. | Integer a = 5 Integer b = 2 Returns false since 5 is not equals to 2 |
=== | a === b | Exact Equality Operator | Not only compares value of a and b, but also check the data type. If a and b are equal with the same data type, then it returns True else False. | Integer a = 2 String b = ‘2’ Although value is same for both variables, it returns false since data type is different for a and b |
>= | a >= b | Greater than or equal to Operator | Returns true if a is greater than or equal to b | Integer a = 5 Integer b = 2 5 >= 2 // True |
<= | a <= b | Less than or equal to Operator | Returns true if a is less than or equal to b | Integer a = 1 Integer b = 1 1 <= 1 //True |
!= | a != b | Inequality Operator | Returns true if value of a is not equals to the value of b. | Integer a = 5 Integer b = 2 5 != 2 //True |
!== | a !== b | Exact Inequality Operator | Returns true if data type and value of both the variables a and b are not equal. | Integer a = 5 Integer b = 2 5 !== 2 //false |
0 Comments