Which are the Expression Operators, Apex supports in Salesforce?

Asked 24-Jan-2018
Viewed 1060 times

1 Answer


2

In SalesForce Visualforce uses Operators to join expressions together to create compound expressions, and Operators must be used within Visualforce expression syntax to be evaluated.

Apex supported operator are as follows

Operator NameOperator Syntax Description
Assignment operator=x = y This operator Assigns the value of y to the L-value x. Note that the data type of x must match the data type of y, and cannot be null.
Addition assignment operator+=x += y This operator Adds the value of y to the original value of x and then reassigns the new value to x. See + for additional information. x and y cannot be null.
Division assignment operator /=x /= yThis operator Divides the original value of x with the value of y and then reassigns the new value to x. Note that x and y must be Integers or Doubles, or a combination. x and y cannot be null.
Subtraction assignment operator-=x -= yThis operator Subtracts the value of y from the original value of x and then reassigns the new value to x. Note that x and y must be Integers or Doubles, or a combination. x and y cannot be null
Multiplication assignment operator*=x *= yThis operator Multiplies the value of y with the original value of x and then reassigns the new value to x. Note that x and y must be Integers or Doubles, or a combination. x and y cannot be null.
Multiplication assignment operator  *=x *= y This operator Multiplies the value of y with the original value of x and then reassigns the new value to x. Note that x and y must be Integers or Doubles, or a combination. x and y cannot be null.
assignment operator|=x |= yIf var x is a Boolean, and var y is a Boolean, and both false, then var x remains false. Otherwise, var x is assigned the value of true. x and y cannot be null.
AND assignment operator &=x &= yIf var x, a Boolean, and y, a Boolean, are both true, then x remains true. Otherwise, x is assigned the value of false. x and y cannot be null.
Bitwise shift left assignment operator<<=x <<= yShifts each bit in x to the left by y bits so that the high order bits are lost, and the new right bits are set to 0. This value is then reassigned to x.
Bitwise shift right signed assignment operator>>=x >>= yShifts each bit in x to the right by y bits so that the low order bits are lost, and the new left bits are set to 0 for positive values of y and 1 for negative values of y. This value is then reassigned to x.
Bitwise shift right unsigned assignment operator>>>=x >>>= yShifts each bit in x to the right by y bits so that the low order bits are lost, and the new left bits are set to 0 for all values of y. This value is then reassigned to x.
Ternary operator? :x ? y : zThis operator acts as a short-hand for if-then-else statements. If x, a Boolean, is true, y is the result. Otherwise, z is the result. Note that x cannot be null.
AND logical operator&&x && y

If var x, a Boolean, and var y, a Boolean, are both true, then the expression evaluates to true. Otherwise, the expression evaluates to false.

Note: && has precedence over ||

This operator exhibits “short-circuiting” behavior, which means y is evaluated only if x is true. x and y cannot be null.

OR logical operator ||x || y

If var x, a Boolean, and var y, a Boolean, are both false, then the expression evaluates to false. Otherwise, the expression evaluates to true.

Note: && has precedence over ||

This operator exhibits "short-circuiting" behavior, which means y is evaluated only if x is false. x and y cannot be null.

Equality operator==x == y

If the value of var x equals the value of var y, the expression evaluates to true. Otherwise, the expression evaluates to false.

Exact equality operator===x === yIf var x and var y reference the exact same location in memory, the expression evaluates to true. Otherwise, the expression evaluates to false.
Less than operator<x < yIf var x is less than var y, the expression evaluates to true. Otherwise, the expression evaluates to false.
Greater than operator>x > yIf var x is greater than var y, the expression evaluates to true. Otherwise, the expression evaluates to false.
Less than or equal to operator<=x <= yIf var x is less than or equal to var y, the expression evaluates to true. Otherwise, the expression evaluates to false.
Greater than or equal to operator>=x >= yIf var x is greater than or equal to var y, the expression evaluates to true. Otherwise, the expression evaluates to false.
Inequality operator!=x != yIf the value of var x does not equal the value of var y, the expression evaluates to true. Otherwise, the expression evaluates to false.
Exact inequality operator!==x !== yIf var x and var y do not reference the exact same location in memory, the expression evaluates to true. Otherwise, the expression evaluates to false.
Addition operator+x + yThis will Adds the value of x to the value of y.
Subtraction operator-x - yThis will Subtracts the value of y from the value of x.
Multiplication operator*x * yThis will Multiplies x, an Integer or Double, with y, another Integer or Double. Note that if a double is used, the result is a Double.
Division operator/x / yThis will Divides x, an Integer or Double, by y, another Integer or Double. Note that if a double is used, the result is a Double.
Logical complement operator!!xThis will Inverts the value of a Boolean, so that true becomes false, and false becomes true.
Unary negation operator--xThis will Multiplies the value of x, an Integer or Double, by -1. Note that the positive equivalent + is also syntactically valid, but does not have a mathematical effect.
Increment operator++x++
++x

This will Adds 1 to the value of x, a variable of a numeric type. If prefixed (++x), the expression evaluates to the value of x after the increment. If postfixed (x++), the expression evaluates to the value of x before the increment.
Decrement operator--x--
--x

This will Subtracts 1 from the value of x, a variable of a numeric type. If prefixed (--x), the expression evaluates to the value of x after the decrement. If postfixed (x--), the expression evaluates to the value of x before the decrement.
Bitwise AND operator&x & yANDs each bit in x with the corresponding bit in y so that the result bit is set to 1 if both of the bits are set to 1. This operator is not valid for types Long or Integer.
Bitwise OR operator|x | yORs each bit in x with the corresponding bit in y so that the result bit is set to 1 if at least one of the bits is set to 1. This operator is not valid for types Long or Integer.
Bitwise exclusive OR operator^x ^ yExclusive ORs each bit in x with the corresponding bit in y so that the result bit is set to 1 if exactly one of the bits is set to 1 and the other bit is set to 0.
Bitwise exclusive OR operator^=x ^= yExclusive ORs each bit in x with the corresponding bit in y so that the result bit is set to 1 if exactly one of the bits is set to 1 and the other bit is set to 0. Assigns the result of the exclusive OR operation to x.
Bitwise shift left operator<<x << yThis will Shifts each bit in x to the left by y bits so that the high order bits are lost, and the new right bits are set to 0.
Bitwise shift right signed operator>>x >> yThis will Shifts each bit in x to the right by y bits so that the low order bits are lost, and the new left bits are set to 0 for positive values of y and 1 for negative values of y.
Bitwise shift right unsigned operator>>>x >>> yThis will Shifts each bit in x to the right by y bits so that the low order bits are lost, and the new left bits are set to 0 for all values of y.
Parentheses()(x)This will Elevates the precedence of an expression x so that it is evaluated first in a compound expression.