+ Start a Discussion
Gerbrand SpaansGerbrand Spaans 

Difference between result from developer console and Illuminated Cloud

We are trying to test some funcitonality and found that the below snippet of code, when executed anonymously, can have different results. When executed on a sandbox using Developer Console, we get an error, saying that it is impossible to do this. But when executed anonymously through the Illuminated Cloud plugin from IntelliJ we get the result 'Success'. 
// Create account
Account a = new Account(Name = 'Donald Duck');
// create contact and relate to account
Contact ct = new Contact(FirstName = 'Donald', LastName = 'Duck', AccountId = a.Id);

// get recordtype Id
RecordType rt = [SELECT Id FROM RecordType WHERE IsPersonType = true And SobjectType = 'Account'];
// set record type id to person account
Account acc = [SELECT Id, RecordTypeId FROM Account WHERE Id = :a.Id];
acc.RecordTypeId = rt.Id;
// update account to person account
Anyone any ideas why this might happen? 
J DoveJ Dove
What specifically is the error that you are receiving when using Developer Console? Also, are you certain the user you specified in the Illuminated Cloud setup is the same user you used to login into the UI/Developer Console? My initial hunch is a user permissions issue.
Daniel van der KolkDaniel van der Kolk
The error we get is "System.DmlException: Update failed. First exception on row 0 with id 0019E00000SMUaJQAX; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Cannot specify any additional fields when marrying or separating a Person-Account: []"

And this is not really an unexpected error, but the weird thing is that this piece of code is actually working when I run it in the Anonymous Apex tab in the IlluminatedCloud plugin. The users we use are the same.