3

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";
            }
        }
    }
}
4
  • [This indicates Salesforce is expecting Business Account related fields and not Person Account ones] -- This is not correct. Business Account do not have FirstName field, it's a Person Account field.
    – Jayant Das
    Commented Dec 17, 2018 at 13:48
  • Yeah Person Accounts have FirstName... the first part of the error says "Bad field names : FirstName" which means it's not expecting a Person Account. Commented Dec 17, 2018 at 13:50
  • I see what you are saying, I misread it.
    – Jayant Das
    Commented Dec 17, 2018 at 13:53
  • In case when the LastName is blank/empty, does your request also consist a value for the field FirstName?
    – Jayant Das
    Commented Dec 17, 2018 at 14:11

2 Answers 2

4

If you are inserting a Person Account, LastName is a required field. You can't make up for missing required fields in a trigger. That is a blanket rule for all objects.

Since there is no LastName, Salesforce interprets the insert as a Business Account. And Person fields like FirstName are invalid in that case.

The only solution is to ensure the request always includes a value for LastName.

1

Based on a quick test, here's how you can fix your issue.

The cause of the error:

Account: bad field names on insert/update call: FirstName: [FirstName] salesforce

seems to be because your request still consists of a value for FirstName field provided in the request even if you are not providing the LastName value.

The presence of the field LastName seems to determine if the incoming Account is a Person or Business Account type. If the request doesn't consist of a value for LastName field, then you will also need to make sure that you remove any FirstName field references from it. And that, you will need to provide the Name field so that the Account will be treated as a Business Account.

2
  • But the problem is the User inserting the record has a default Account Record Type of "Person Account" (via their profile). If the user hasn't specified the RecordTypeId it should automatically assume this is a Person Account shouldn't it? and thus the FirstName field should be valid. Commented Dec 17, 2018 at 14:57
  • You don't need to provide RecordTypeId or RecordType's Name. Based on the test that I did, the validation in the trigger is evaluated only if you provide LastName and that's the time it evaluates the RecordTypeId to be a Person Account and gets further in the if block. The time you remove LastName but if at all the request still consists of a FirstName, then it does not treat or default it to Person Account.
    – Jayant Das
    Commented Dec 17, 2018 at 15:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .