Skip to content

Instantly share code, notes, and snippets.

@gitmatheus
Last active April 11, 2017 20:44
Show Gist options
  • Save gitmatheus/0ff6c2a1d179663f2a5d0fc3ef626de7 to your computer and use it in GitHub Desktop.
Save gitmatheus/0ff6c2a1d179663f2a5d0fc3ef626de7 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