• Gerbrand Spaans
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
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');
Database.insert(a);
// create contact and relate to account
Contact ct = new Contact(FirstName = 'Donald', LastName = 'Duck', AccountId = a.Id);
Database.insert(ct);

// 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
Database.update(acc);
Anyone any ideas why this might happen?