Last active
December 19, 2015 00:38
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
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
Attention, this fails in all API versions <= 26
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
Related https://gist.github.com/kevinohara80/5867465
Related https://gist.github.com/ChrisBland/5721696