• Constance Rouge 8
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi Everyone,

I have an apex class that merges two person accounts in this piece of code (knowing all the accounts in the org are person accounts, so I am sure the result of the queries isn't a business account):
Account masterAcct= [SELECT Id, personEmail, Name FROM Account WHERE PersonEmail= :leadToConvertEmail LIMIT 1];
Account newAcct = [SELECT Id, PersonEmail, Name FROM Account WHERE Id= :acctIdToCheck LIMIT 1];

merge masterAcct newAcct;

But I get this error: 
INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on insert/update call: Name: [Name]

If I change my code and delete Name (wether I add FirstName and LastName in the query or not):
Account masterAcct= [SELECT Id, personEmail FROM Account WHERE PersonEmail IN :leadsEmailList LIMIT 1];
Account newAcct = [SELECT Id, PersonEmail FROM Account WHERE Id= :acctIdToCheck LIMIT 1]; 

//Same result with: Account masterAcct= [SELECT Id, personEmail, salutation, firstName, lastName FROM Account WHERE PersonEmail IN :leadsEmailList LIMIT 1];
//And: Account newAcct = [SELECT Id, PersonEmail, salutation, firstName, lastName FROM Account WHERE Id= :acctIdToCheck LIMIT 1];

merge masterAcct newAcct;
I get the following error:
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.Name

Therefore, is there a way to use merge with two person accounts?

Thanks or your help!

Constance
Hi Everyone,

I have an apex class that merges two person accounts in this piece of code (knowing all the accounts in the org are person accounts, so I am sure the result of the queries isn't a business account):
Account masterAcct= [SELECT Id, personEmail, Name FROM Account WHERE PersonEmail= :leadToConvertEmail LIMIT 1];
Account newAcct = [SELECT Id, PersonEmail, Name FROM Account WHERE Id= :acctIdToCheck LIMIT 1];

merge masterAcct newAcct;

But I get this error: 
INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on insert/update call: Name: [Name]

If I change my code and delete Name (wether I add FirstName and LastName in the query or not):
Account masterAcct= [SELECT Id, personEmail FROM Account WHERE PersonEmail IN :leadsEmailList LIMIT 1];
Account newAcct = [SELECT Id, PersonEmail FROM Account WHERE Id= :acctIdToCheck LIMIT 1]; 

//Same result with: Account masterAcct= [SELECT Id, personEmail, salutation, firstName, lastName FROM Account WHERE PersonEmail IN :leadsEmailList LIMIT 1];
//And: Account newAcct = [SELECT Id, PersonEmail, salutation, firstName, lastName FROM Account WHERE Id= :acctIdToCheck LIMIT 1];

merge masterAcct newAcct;
I get the following error:
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.Name

Therefore, is there a way to use merge with two person accounts?

Thanks or your help!

Constance