We are seeing a test failure in a couple of our Continuous Integration builds (that deploy the same code) with the error:
System.SObjectException: Contact.AccountId does not belong to SObject type Contact
The error is occurring in the put
in this code (where the SObjectField
array is hard coded and so has been successfully compiled):
public static SObject copyFieldsToNewSob(SObject sob, SObjectField[] fields) {
SObject result = sob.getSObjectType().newSObject();
for (SObjectField f : fields) {
if (!String.valueOf(f).equalsIgnoreCase('Id')) {
result.put(f, sob.get(f));
}
}
return result;
}
One org fails all the time and the other 2 out of 3 times.
I'll raise a case, but before I do is anyone else seeing this or knows if it will be fixed soon?