You need to sign in to do that
Don't have an account?

Internal Salesforce Error when inserting list<contact> on deserialized class instance
Hello,
I recently had a test started rendering an Internal Salesforce Error without any code changes on my end. I have managed to write a simple test class that demonstrates the issue. Basically, this seems to be related to deserializing JSON to a class and then attempting to insert a list of Contacts in a variable on the class.
Here is a simple example which will render the error:
public with sharing class InsertJSONContactList { public string someVar; public list<Contact> insertContacts; public InsertJSONContactList () { insertContacts = new list<Contact>(); someVar = 'hello'; } //Test public static testMethod void testSerialize() { // Instantiate the class InsertJSONContactList ext = new InsertJSONContactList(); // Make sure we are connected to reality system.assertEquals('hello',ext.someVar); // Add a contact to the list ext.insertContacts.add(new Contact(LastName='Rogerson', Email='rogerson@superfaketestemail.org')); // Insert the list, this will work insert ext.insertContacts; // Reset the list for later... ext.insertContacts = new list<Contact>(); // Serialize the class string jsonExt = JSON.serialize(ext); // Deserialize the string JSONParser parser = JSON.createParser(jsonExt); Type wrapperType = Type.forName('InsertJSONContactList'); InsertJSONContactList nwExt = (InsertJSONContactList) parser.readValueAs(wrapperType); // Make sure we are still connected to reality system.assertEquals('hello',nwExt.someVar); // Add a contact to our list nwExt.insertContacts.add(new Contact(LastName='Davidson', Email='davidson@superfaketestemail.org')); // Insert the list. Internal Salesforce Error insert nwExt.insertContacts; } }
This looks like a bug to me, especially since it only recently started happening after working fine for some months. However, I would love to hear of any suggestions for workarounds. I will have to refactor quite a bit of code to get around this problem.
This passes in the new release. Just hold on for one more week! :)