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

DUPLICATE_VALUE: duplicate value found #10

Open
andrii-solokh opened this issue Aug 25, 2020 · 5 comments
Open

DUPLICATE_VALUE: duplicate value found #10

andrii-solokh opened this issue Aug 25, 2020 · 5 comments

Comments

@andrii-solokh
Copy link

Hello, getting this error while running tests.

TestDataFactory.TestDataFactoryException: Unable to insert "QuoteLineItem.product2" records: 
DUPLICATE_VALUE: duplicate value found: <unknown> duplicates value on record with id: <unknown> [Name=test0].

Seems 'TestDataFactory' doesn't count sames object number, and if creating record which depends on object 'X' and object 'Y' which depends also on 'X', two objects of 'X' will be created, but with same 'Name', that is causing my error.

It simply solved by specifying the name for one of 'X' objects, so another 'X' is default 'test0'.
It would be great to make the counter, to prevent this error.

@benahm
Copy link
Owner

benahm commented Aug 25, 2020

Hello @andrii-solokh

I you trying to link to the same object, you can do that in two steps like this example

Create 10 Cases related to 10 Accounts

Create a list of Acount sObjects and link them to a list of 10 Case sObjects

List<Account> accList = TestDataFactory.createSObjectList('Account', new Map<String,Object>{
  'Description' => 'Account Description'
},10);
List<Case> caseList = TestDataFactory.createSObjectList('Case', new Map<String,Object>{
  'Account' => AccList,
  'Contact.Account' => AccList
},10);

@andrii-solokh
Copy link
Author

@benahm
Thank you for the fast response. But it seems you didn't get my idea.

AObj__c, req. fields :
- Lookup BObj__c
- Lookup CObj__c

BObj__c, req. fields:
- Lookup DObj__c

CObj__c, req. fields:
- Lookup DObj__c

In this situation, if you try to create AObj__c with only one action 'TestDataFactory.createSObject', it will produce error, because DObj__c will have same default name 'test0'.

@benahm
Copy link
Owner

benahm commented Aug 25, 2020

Hello @andrii-solokh

I would do it like this

DObj__c dRecord = TestDataFactory.createSObject('DObj__c')

AObj__c aRecord = TestDataFactory.createSObject('AObj__c',new Map<String,Object>{
     BObj__r.DObj__r => dRecord,
     CObj__r.DObj__r => dRecord
});

Hope this help.

@andrii-solokh
Copy link
Author

Ye, but if those should be different records, not same. And also if you don't care, just need to create test data as fast as possible, using one line.

TestDataFactory.createSObject.....

I think that could be useful.

@tet3
Copy link

tet3 commented Oct 27, 2022

I ran into this just trying to get all the tests in TestDataFactory_Test to pass, before I even started using the test factory. It's a definite issue in orgs that have Duplicate Rules on Name fields with Block actions.

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

3 participants