Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create PersonAccounts when calling createSObjectList() method #14

Open
ankittaneja opened this issue Sep 10, 2021 · 0 comments

Comments

@ankittaneja
Copy link

I am trying to do

List<Account> PersonAccs = (Account[]) TestFactory.createSObjectList(new Account(), 100, 'TestFactoryDefaults.PersonAccountDefaults');

And I get the following error:

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]

LastName is a required field for PersonAccounts which is being provided in the defaults class. If I add Account.SObjectType => Account.LastName to nameFieldMap at Line 108, then I am unable to create Business Accounts.

There must be a way to say Name or LastName is required field depending upon what we are inserting: Accounts or PersonAccounts via createSObjectList() method.

Your suggestion: It would probably be better to refactor the code a bit and make a method to determine the name field since the logic is getting more complicated.

Please let me know if I can help.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant