Skip to content

Instantly share code, notes, and snippets.

@gitmatheus
Created October 20, 2021 21:50
Show Gist options
  • Save gitmatheus/86fa366c6d2f33d7544ebf1fc5318213 to your computer and use it in GitHub Desktop.
Save gitmatheus/86fa366c6d2f33d7544ebf1fc5318213 to your computer and use it in GitHub Desktop.
/******************************************
Imagine three strings:
- one with a single space
- one null
- one not empty and not null
******************************************/
String singleSpaceString = ' ';
String nullString = null;
String notEmptyString = 'Samwise Gamgee is the real hero';
// because, let's be honest...
// Now lets concatenate these strings to see
// what Salesforce is doing under the hood:

String concatenatedText =
singleSpaceString + nullString + notEmptyString;
// This is the result:

|DEBUG|concatenatedText: nullSamwise Gamgee is the real hero
// What if we concatenate the empty and null variables only?
concatenatedText = singleSpaceString + nullString;
// This is the result:

|DEBUG|concatenatedText: null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment