Free Salesforce Developers Tutorials >

Chapter 3 - Apex Datatypes and Operators >

Equality Operator

Equality Operator

What You’ll Learn

S2 Labs

What Is Equality Operator In Apex?

If a value of X equals Y, the expression evaluates to true otherwise the expression evaluates to false.
  • User-defined types are compared by reference which means that the 2 objects are equal if they reference the same location in the memory.
  • You can override this default comparison behaviour by equals() and hashcode() methods in your class to compare object values instead.
  • Unlike java(==), in apex it compares object value equality not reference equality except for user-defined types..
  • String comparison using(==) is case insensitive.
  • ID comparison using == is case-sensitive.
Integer a[] = new Integer[5]; 
Integer b[] = new Integer[5]; 
for(Integer i=0; i<5; i++) 
  • Arrays(==) performs a deep check of all the values before returning its result. Likewise for collection and built-in apex objects.
  • The comparison of any two values can never result in null though X and Y can be literal null.
  • SOQL and SOSL use ‘=’ for their equality operator not ‘==’.

What Is Exact Equality Operator(===)?

If X and Y reference the exact same location in memory, the expression evaluates to true otherwise false.
FirstClass fc = new FirstClass();
FirstClass fc2 = new FirstClass();

What Is Exact Inequality Operator(!==)?

If X and Y do not reference the exact same location in memory, the expression evaluates to true otherwise false.

Download Study Material

Get access to exclusive study material for Salesforce Certification and ace your exams!

Download Now

Our Salesforce Certification Courses

Hey there! Glad you made it through our Salesforce Developer Training for beginners . But wait! We've got some high-in-demand Salesforce courses for you to take your Salesforce skills to the next level, making you a desired professional in the Salesforce job market.

Post a Comment

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