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

Exception: duplicate value found: <unknown> duplicates value on record with id: <unknown>: []
Hi
I'm new to this so please forgive my ignorance.
I'm getting the exception when:
- insert an Opportunity
- insert a ContentVersion
- post the new ContentVersion to the Opportunity's chatter feed
- delete the Opportunity
Does anybody know why, and if so, how to overcome the exception?
I am using API version 26.0
Thanking you in advance
private static void TestOpportunityDeletion()
{
// create an opportunity
Opportunity opp = new Opportunity() ;
opp.Name = 'Test Name' ;
opp.StageName = 'Test Stage Name' ;
opp.CloseDate = Date.Today() ;
insert opp ;
// attach a document to its chatter feed
ContentVersion doc = new ContentVersion() ;
doc.Title = 'Test Version' ;
doc.PathOnClient = 'test version.docx' ;
doc.VersionData = Blob.ValueOf( 'test content' ) ;
doc.Origin = 'H' ;
insert doc ;
FeedItem post = new FeedItem() ;
post.Type = 'ContentPost' ;
post.ParentID = opp.Id ;
post.RelatedRecordID = doc.id ;
insert post ;
// delete the opportunity
delete opp ;
}
delete post;
Then your code will work.
All Answers
delete post;
Then your code will work.
Thanks for that - it works a treat.
However, does that mean for every SalesForce object that potentially has a chatter feed, we must introduce a trigger which deletes its feed items before it is deleted itself?
When you delete a record, the Chatter post on the record will also be deleted, but the file will be left.
In your case, it is a little strange. When you delete the record from the interface, you got the same error.
I will try to figure it out later, when I have time.