function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deepak PansariDeepak Pansari 

duplicate value found: <unknown> duplicates value on record with id: <unknown>

Hi All,

We are getting this error while inserting Case Manual share records through Apex manual sharing.

duplicate value found: <unknown> duplicates value on record with id: <unknown>

We are not able to identify and reproduce this error.

Can someone provide some inputs on cause of this error?

Thanks
Deepak
Jai SureshJai Suresh
Are you sure you are getting this error while inserting? Because, you cannot specify ids for records that you are inserting.

If you are updating/upserting, then the list you are updating contains more than one record with the same id.

Use a set first to create an unique set of ids and create a list of records based on that set. Update this newly created list.
Deepak PansariDeepak Pansari
Yes, I am sure. I am inserting case share record via apex code. and there is no ID is specified there.
James LoghryJames Loghry
You get this error by violating some unique constraint.  In the Case Sharing scenario, it's likely that the Case is already shared with the user you're attempting to share it with.  Before you insert the sharing record, I would query to see if they already exist in the sharing records.  Also, you might want to check you're not inserting two records, one right after the other.  I ran into this scenario yesterday, actually.
Deepak PansariDeepak Pansari
Hi, Even though if manual share is alreay there and if i try to insert new record then also i did not get any error.

Below are samle code where i tring to insert same share twice and not getting any error.

List<CaseShare> sharesToCreate = new List<CaseShare>();
for(integer i=0;i<2;i++)
{
CaseShare cs = new CaseShare();
cs.CaseAccessLevel = 'edit';
cs.CaseId = '500f0000005GEIy';
cs.UserOrGroupId = '00540000001DUnk';
sharesToCreate.add(cs);
}
insert sharesToCreate;

Yahor VolkauYahor Volkau
I had the same problem when tried deploy lookup with filter: there is history tracking in custom lookup field with look up filters, when the filter refers to a field with tracking to custom object in the same deployment transaction.
This solution resolved problem: just remove the History Tracking on the custom field and then deploy. Once the deployment is completed, history tacking can be enabled on the custom filed as part of post deployment step.
https://success.salesforce.com/issues_view?id=a1p30000000T5hTAAS
TJ BrownTJ Brown

@yahor I have run into this too.  Except turing off field history tracking in my target environment broke other parts of my deployment as field history is ON in my source.  And if you turned off field history tracking in the target, then turned it back on again in the post deployment steps... won't you miss the field history selections that are included in your deployment metdata? How did you get around this?    

For me, i found that I can manually create the lookup fields that have filters in the target environment (without the filter , just provide the lookup), then i can deploy from my source environment with filters, FLS, etc... just fine. 

Why is this happening I wonder? -tjb

Ruchi AggarwalRuchi Aggarwal
This error occurs becuase of duplicate entery either during  insertion or during deployment also getting this kind of issue.
Just need to check  duplicate entery in the CSV file or Package.xml
Nilesh PabuwalNilesh Pabuwal
One of the reason is -  Class Name would be same causing this issues
sru1209 nsru1209 n
Can someone please guide me with the solution.Stuck with a similar issue.