+ Start a Discussion

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



I'm new to this so please forgive my ignorance.


I'm getting the exception when:


  1. insert an Opportunity
  2. insert a ContentVersion
  3. post the new ContentVersion to the Opportunity's chatter feed
  4. 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 ;

Best Answer chosen by Admin (Salesforce Developers) 
Jia HuJia Hu
Before ' delete opp ;' add
delete post;

Then your code will work.

All Answers

Jia HuJia Hu
Before ' delete opp ;' add
delete post;

Then your code will work.
This was selected as the best answer

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?

Jia HuJia Hu
Usually you don't need to do this.

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.