• Gerbrand Spaans
  • 0 Points
  • Member since 2016

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 0
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?