/
Query and Update a Person Account
Query and Update a Person Account
Because Person Accounts are tightly coupled with Contacts, the Name
field is compound and cannot be updated. Instead you must update FirstName
and LastName
.
SalesforceSession salesforceSession = new SalesforceSession(new LoginDetails("username@example.com", "salesforcePassword"));
AccountService accountService = new AccountService(salesforceSession);
// This queries an existing Account record by 'Name' and retrieves all fields.
Account acct = accountService.GetSingleByFieldEquals(Account.Fields.Name, "John Smith");
// Change the FirstName.
acct.InternalFields[Contact.Fields.FirstName.Name] = "Jack";
// If we tried to update now, Salesforce would return INVALID_FIELD_FOR_INSERT_UPDATE error because we can't update 'Name'.
// Remove Name from the fields to be updated.
acct.InternalFields.Remove(Account.Fields.Name.Name);
// Now we can update successfully.
SaveResult result = accountService.UpdateEntity(acct);
Assert(result.success);
Related content
Create a new Person Account
Create a new Person Account
More like this
Update an Existing Account
Update an Existing Account
More like this
Update an Existing Lead
Update an Existing Lead
More like this
Working with the SalesforceGenericEntity
Working with the SalesforceGenericEntity
More like this
Master-Child Child-to-Parent Query Example
Master-Child Child-to-Parent Query Example
More like this
Changing the Sitecore Username (Optional) (Pre-Sitecore 9)
Changing the Sitecore Username (Optional) (Pre-Sitecore 9)
More like this