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
phil.vaseyphil.vasey 

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:

 

  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
phil.vaseyphil.vasey

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.
lenilac joyislenilac joyis
you can check your code for this link https://apkloo.com/chatgpt-apk/ , and generate the more new codes..
Rupesh VermaRupesh Verma

You don't necessarily need to introduce a trigger for every Salesforce object that potentially has a chatter feed in order to delete its feed items before deletion . (https://gbmod.net/download-gbwhatsapp-apk/)
Salesforce provides the option to enable the "Delete this record but keep its feed items" checkbox on the object's delete confirmation page. By selecting this option, you can delete the object while retaining its associated feed items.