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
Here is the original String/Id issue we were seeing in Summer '13.
The trigger is pretty self-explanatory. Just install and insert a lead. FirstName is not an instance of an ID!!!!
UPDATE:
We have now verified that this does not fail on API version 28, and 27 but will fail on version 26 and below.
CAN WE PLEASE GET THIS MOVED TO THE KNOWN ISSUES LIST???
Case #09352330 (Closed for some reason)
Case #09410158