function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shilpa k vShilpa k v 

What is difference between null and '' operator in apex code?

Naval Sharma4Naval Sharma4
Hi Shilpa,

null and '' operator seems similar but there is a slight difference between these.
If you want to check that a string is empty then you can go with ' ' but when you need to check with refernces like ID and collections then you have to use null.

These links are better resource so check it.
https://success.salesforce.com/answers?id=90630000000hTOsAAM 

https://developer.salesforce.com/forums/?id=906F00000008nV0IAI
Naval Sharma4Naval Sharma4
Hi Shilpa,

One more difference is that If you declare a variable and don't initialize it with a value, it will be null. In essence, null means the absence of a value. You can use '' with strings and in that case checking for '' will give you true if string has initialized but doesn't have any content.