Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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