Skip to content

Instantly share code, notes, and snippets.

@kevinohara80
Last active December 19, 2015 00:38
Show Gist options
  • Save kevinohara80/5869680 to your computer and use it in GitHub Desktop.
Save kevinohara80/5869680 to your computer and use it in GitHub Desktop.
Another Spring '13 String/Id bug having to do with the use of instanceof
trigger IdStringIssueTrigger on Lead (after insert) {
String leadId = Trigger.new[0].Id;
SObject so = [SELECT Id, FirstName, LastName FROM Lead WHERE Id = :leadId];
if(so.get('FirstName') instanceof Id) {
Trigger.new[0].FirstName.addError('Apex thinks this is an ID!!!'); // errors always
}
}
@kevinohara80
Copy link
Author

@kevinohara80
Copy link
Author

Other notes.

This only happens when you are dealing with SObjects and calling SObject.get('SomeVal'). We verfied that..

(lead.FirstName instanceof Id)

...works as expected

@ChrisBland
Copy link

Attention, this fails in all API versions <= 26

@gfee-sfdc
Copy link

Hi all, yes, there was a bug in the product where in some cases instanceof ID will return true on things that are not really IDs. We fixed this in version 27 but versioned it so that <= 26 still sees the old (broken) behavior. We did this to minimize the risk of breaking existing code. I think getting this into the known issues list sounds like the right way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment