You need to sign in to do that
Don't have an account?

Error while testing delete contacts
I am getting this error while trying to delete contacts in a test class
System.DmlException: Delete failed. First exception on row 0 with id 003Q0000018OY8CIAW; first error: INVALID_PERSON_ACCOUNT_OPERATION, cannot reference person contact: []
Deletion works fine if I run the code normally but in the test I get this, how can I work around this for testing purposes or should my query be changed to avoid person accounts?
delete[select id,name from Contact where name like '%test%'];
System.DmlException: Delete failed. First exception on row 0 with id 003Q0000018OY8CIAW; first error: INVALID_PERSON_ACCOUNT_OPERATION, cannot reference person contact: []
Deletion works fine if I run the code normally but in the test I get this, how can I work around this for testing purposes or should my query be changed to avoid person accounts?
delete[select id,name from Contact where name like '%test%'];
Yes, you have to avoid person accounts in your query by using 'Account.isPersonAccount = false' clause.
The reason behind this is, you can only modify the person contact but can not create or delete it. It will automatically be created and deleted with person account. You may refer #4 and #5 in document https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_guidelines_personaccounts.htm .
Thanks,
Anjita
All Answers
You can filter person accounts by using, '.Account.isPersonAccount = false' in WHERE CLAUSE.
-Thanks,
TK
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Yes, you have to avoid person accounts in your query by using 'Account.isPersonAccount = false' clause.
The reason behind this is, you can only modify the person contact but can not create or delete it. It will automatically be created and deleted with person account. You may refer #4 and #5 in document https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_guidelines_personaccounts.htm .
Thanks,
Anjita
Let us know if this will help you