Expression Operators In Salesforce

by | Jun 22, 2022 | Salesforce

Home » Salesforce » Expression Operators In Salesforce

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:

OperatorSyntaxName Description Example
=a = bAssignment Operatorassigns the value of b to a.Integer a = 5

Integer b = 2

a = 2

+=a += bAddition Assignment OperatorCorresponds 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 -= bSubtraction Assignment OperatorCorresponds 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 *= bMultiplication Assignment OperatorCorresponds 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 /= bDivision Assignment OperatorCorresponds 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 && bAND Logical OperatorRight 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 || bOR Logical OperatorIf 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 == bEquality OperatorIt 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 === bExact Equality OperatorNot 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 >= bGreater than or equal to OperatorReturns true if a is greater than or equal to bInteger a = 5

Integer b = 2

5 >= 2 // True

<=a <= bLess than or equal to OperatorReturns true if a is less than or equal to bInteger a = 1

Integer b = 1

1 <= 1 //True

!=a != bInequality OperatorReturns true if value of a is not equals to the value of b.Integer a = 5

Integer b = 2

5 != 2 //True

!==a !== bExact Inequality OperatorReturns 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

 

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Author