I have an integration which inserts Person Account records into my Salesforce org. Sometimes the integration doesn't include a LastName (if the user hasn't provided one) which causes the integration to receive an error from Salesforce.
To remedy this I have created a trigger (before update and insert) which populates the LastName field if its empty.
I have noticed that if the LastName
attribute is provided (even it its blank) the trigger works as expected, however if the LastName
attribute is not provided at all I get the following error:
Account: bad field names on insert/update call: FirstName: [FirstName] salesforce
This indicates Salesforce is expecting Business Account related fields and not Person Account ones. The integration itself doesn't set the RecordTypeID to "Person Account", this is done by the assigned Profiles default Account Record Type setting. In my Integration if the RecordTypeId is passed in the payload the insert works as expected.
Does anyone know why the default Person Account record type setting doesn't do this without explicitly specifying it in the payload? The reason I don't want to specify is so I don't need to hard-code ID's or even developer names in my integration.
Edit: Here's a simplified version of the trigger I'm using FYI.
trigger AccountTrigger on Account (before insert, before update) {
if(Trigger.isBefore) {
for(Account newAc : Trigger.new) {
// check if PersonAccount and LastName is null
if(newAc.isPersonAccount && string.isBlank(newAc.LastName)) {
newAc.LastName = "Fake Last Name";
}
}
}
}
FirstName
field, it's a Person Account field.LastName
is blank/empty, does your request also consist a value for the fieldFirstName
?