[SalesForce] Error trying to update a Person Account

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

even though I am not trying to update Name in my Person Account record.

Here is the code:

try {
    Account queriedContact = [SELECT Name 
                          FROM Account 
                          WHERE PersonEmail = 'test@test.com'
                          LIMIT 1];

    queriedContact.Motto__pc = 'My motto';
    update queriedContact;

} catch(Exception e) {
    System.debug('An unexpected error has occurred: ' + e.getMessage());

Any suggestion? Do I need to changes anything in my org settings?


Best Answer

When you use the Name variable in your query, Salesforce is concatenating FirstName, MiddleName, LastName, and Suffix for you, which works fine when doing a query, however when you go to update that record, Salesforce doesn't want the concatenated version.

Try updating your query to not retrieve the name. Use Motto__pc instead. You'll need to query that field if you want to update it anyway.