Skip to content

Instantly share code, notes, and snippets.

@anilsomasundaran
Last active May 10, 2018 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anilsomasundaran/a3e9041a3f56212693d017268c3f84f1 to your computer and use it in GitHub Desktop.
Save anilsomasundaran/a3e9041a3f56212693d017268c3f84f1 to your computer and use it in GitHub Desktop.
sobject obj = null;
switch on obj {
//checks whether the obj is an instance of Account.
//if yes, obj is casted to acc with relevant values
when Account acc {
System.debug('account ' + acc);
}
//checks whether the obj is an instance of Contact.
//if yes, obj is casted to con with relevant values
when Contact con {
System.debug('contact ' + con);
}
//checks obj == null
when null {
System.debug('null');
}
// default block
when else {
System.debug('default');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment