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
MarcoTimbaMarcoTimba 

DmlException DUPLICATE_VALUE on Delete Operation

Hi,

when attempting to delete a list of FeedItems I'm getting the following error:

 

EXCEPTION: System.DmlException: Delete failed.

First exception on row 1 with id 0D5G000000h9c6ZKAQ; first error:

DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []

 

As I understand it the DUPLICATE_VALUE error is for then you try an insert/update/upsert and you have a duplicated value in a unique field, I don't understand why is this firing on a DELETE operation.

 

I checked and don't have duplicate FeedItems in the list, I even tried doing:

 

List<FeedItem> fiList = [SELECT Id FROM FeedItem WHERE Id in ('id1', 'id2')];
delete fiList;

 and I'm still getting the same error.

 

I have just one trigger and I alredy tried disabling it and the error still happens.

 

The error doesn't happen always, but I can't find any logic to why is happenning.

 

Any ideas of why this may be happening or how to fix it will be greatly appreciated.

 

Thank you

 

Jia HuJia Hu
This is strange.
Have your tried only delete one record, like
List<Feeditem> fi = [Select Id from Feeditem limit 1];
delete fi;

if it is OK, then delete two records, like
List<Feeditem> fi = [Select Id from Feeditem limit 2];
delete fi;
MarcoTimbaMarcoTimba

Hi Jia,

thank you for your response, I will try deleting just one record and see if that works, if I remember correctly I had already tried and it worked but I want to try it again to make sure, I have already tried with just 2 records and it was still giving the error message.

 

we are hitting this error in more than one Org, but we haven't found the specific steps to be able to create a case that reproduces the error 100% of the time. We are working on this and we find the exact steps that will probably clear out why the delete is failing.

 

The error message that Salesforce is showing is just not being very useful for troubleshooting.

MarcoTimbaMarcoTimba

I kept trying and I narrow it down a bit more:

 

I have this 2 records:

 

-- FeedItem Record 1 --
Body:
CommentCount: 0
ContentDescription:
ContentFileName: image.png
ContentSize: 562
ContentType: image/png
CreatedById: 005G0000002cLfyIAE
CreatedDate: 2012-12-04T13:06:06.000Z
Id: 0D5G000000hDrzZKAS
InsertedById: 005G0000002cLfyIAE
IsDeleted: false
LastModifiedDate: 2012-12-04T13:06:06.000Z
LikeCount: 0
LinkUrl:
ParentId: 001G000000qbl7HIAQ
RelatedRecordId: 068G0000000axlXIAQ
SystemModstamp: 2012-12-04T13:06:06.000Z
Title: Attachment Test (Marco) (Modified v2)
Type: ContentPost

 

-- FeedItem Record 2 --
Body:
CommentCount: 0
ContentDescription:
ContentFileName: image.png
ContentSize: 562
ContentType: image/png
CreatedById: 005G0000002cLfyIAE
CreatedDate: 2012-12-04T13:06:06.000Z
Id: 0D5G000000hDrzaKAC
InsertedById: 005G0000002cLfyIAE
IsDeleted: false
LastModifiedDate: 2012-12-04T13:06:06.000Z
LikeCount: 0
LinkUrl:
ParentId: 001G000000qbl7LIAQ
RelatedRecordId: 068G0000000axlXIAQ
SystemModstamp: 2012-12-04T13:06:06.000Z
Title: Attachment Test (Marco) (Modified v2)
Type: ContentPost

 

I first start doing this in the Apex Execute of the Workbench:
delete [SELECT Id FROM FeedItem WHERE Id IN ('0D5G000000hDrzZKAS', '0D5G000000hDrzaKAC')];

 

I get this:

EXCEPTION: System.DmlException: Delete failed. First exception on row 1 with id 0D5G000000hDrzaKAC; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []
STACKTRACE: AnonymousBlock: line 1, column 1
LINE: 1 COLUMN: 1

26.0 APEX_CODE,DEBUG
Execute Anonymous: delete [SELECT Id FROM FeedItem WHERE Id IN ('0D5G000000hDrzZKAS', '0D5G000000hDrzaKAC')];
04:24:25.050 (50092000)|EXECUTION_STARTED
04:24:25.050 (50102000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
04:24:25.426 (426775000)|CODE_UNIT_STARTED|[EXTERNAL]|01qG0000000uAql|dev1L4M.FeedItemTrigger on FeedItem trigger event AfterDelete for [0D5G000000hDrzZ]
04:24:25.427 (427200000)|ENTERING_MANAGED_PKG|
04:24:25.609 (609307000)|CODE_UNIT_FINISHED|dev1L4M.FeedItemTrigger on FeedItem trigger event AfterDelete for [0D5G000000hDrzZ]
04:24:25.618 (618690000)|EXCEPTION_THROWN|[1]|System.DmlException: Delete failed. First exception on row 1 with id 0D5G000000hDrzaKAC; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []
04:24:25.619 (619946000)|FATAL_ERROR|System.DmlException: Delete failed. First exception on row 1 with id 0D5G000000hDrzaKAC; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []

AnonymousBlock: line 1, column 1
04:24:25.619 (619966000)|CODE_UNIT_FINISHED|execute_anonymous_apex
04:24:25.619 (619975000)|EXECUTION_FINISHED

 

Then I do this:
delete [SELECT Id FROM FeedItem WHERE Id IN ('0D5G000000hDrzZKAS', '0D5G000000hDrzaKAC') LIMIT 2];

 

And I get the same error.

 

Then doing this:
delete [SELECT Id FROM FeedItem WHERE Id IN ('0D5G000000hDrzZKAS', '0D5G000000hDrzaKAC') LIMIT 1];

 

Works!

 

26.0 APEX_CODE,DEBUG
Execute Anonymous: delete [SELECT Id FROM FeedItem WHERE Id IN ('0D5G000000hDrzZKAS', '0D5G000000hDrzaKAC') LIMIT 1];
04:26:36.036 (36756000)|EXECUTION_STARTED
04:26:36.036 (36767000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
04:26:36.144 (144615000)|CODE_UNIT_STARTED|[EXTERNAL]|01qG0000000uAql|dev1L4M.FeedItemTrigger on FeedItem trigger event AfterDelete for [0D5G000000hDrzZ]
04:26:36.145 (145085000)|ENTERING_MANAGED_PKG|
04:26:36.267 (267294000)|CODE_UNIT_FINISHED|dev1L4M.FeedItemTrigger on FeedItem trigger event AfterDelete for [0D5G000000hDrzZ]
04:26:36.285 (285182000)|CODE_UNIT_FINISHED|execute_anonymous_apex
04:26:36.285 (285198000)|EXECUTION_FINISHED

 

Doing this again:
delete [SELECT Id FROM FeedItem WHERE Id IN ('0D5G000000hDrzZKAS', '0D5G000000hDrzaKAC') LIMIT 1];

 

I get this error again:
EXCEPTION: System.DmlException: Delete failed. First exception on row 0 with id 0D5G000000hDrzaKAC; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []
STACKTRACE: AnonymousBlock: line 1, column 1
LINE: 1 COLUMN: 1

6.0 APEX_CODE,DEBUG
Execute Anonymous: delete [SELECT Id FROM FeedItem WHERE Id IN ('0D5G000000hDrzZKAS', '0D5G000000hDrzaKAC') LIMIT 1];
04:27:19.045 (45240000)|EXECUTION_STARTED
04:27:19.045 (45251000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
04:27:19.162 (162443000)|EXCEPTION_THROWN|[1]|System.DmlException: Delete failed. First exception on row 0 with id 0D5G000000hDrzaKAC; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []
04:27:19.163 (163440000)|FATAL_ERROR|System.DmlException: Delete failed. First exception on row 0 with id 0D5G000000hDrzaKAC; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []

AnonymousBlock: line 1, column 1
04:27:19.163 (163457000)|CODE_UNIT_FINISHED|execute_anonymous_apex
04:27:19.163 (163467000)|EXECUTION_FINISHED

 

So the problem was not deleting more than one FeedItem at a time, the problem is with a specific FeedItem, I just don't see why that FeedItem is special.

Jia HuJia Hu
It seems something wrong with Salesforce.
If you can so specify the problem, you can ask for the Salesforce support to confirm this.
phil.vaseyphil.vasey

I get the same error (no triggers defined) on a very straightforward test method:

 

private static testmethod void TestOpportunityDelete() {


// insert an opportunity
Opportunity opp = new Opportunity() ;
opp.Name = 'Test Name' ;
opp.StageName = 'Test Stage Name' ;
opp.CloseDate = Date.Today() ;
insert opp ;

// insert a document
ContentVersion doc = new ContentVersion() ;
doc.Title = 'Test Version' ;
doc.PathOnClient = 'test version.docx' ;
doc.VersionData = Blob.ValueOf( 'test content' ) ;
doc.Origin = 'H' ;
insert doc ;

// attach the document to the opportunity's chatter feed
FeedItem post = new FeedItem() ;
post.Type = 'ContentPost' ;
post.ParentID = opp.Id ;
post.RelatedRecordID = doc.id ;
insert post ;

// delete the opportunity
delete opp ;
}

Ashish Sharma 406Ashish Sharma 406
Thanks It's Really Helpful
Ashish Sharma (https://ashish.page/)