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

How to store not repeated objects in a Set

I have a custom object and I want to store it with no objects repeated.
I store them in a Set<custom_object_c> , and Custom_object__c is implementing interface comparable and method compareTo .
If I test the method, it works fine.

But if I try to store 2 cloned objects in the Set , it doesn't works and store it.

How can I do for store not repeated objects?

Subhash GarhwalSubhash Garhwal
Hi David,

Set is a collection of unique elements with no duplicate values.But when you clone any object newly created record's Id is different thats why your set store both these values, otherwise set never store duplicate.
To more details about set follow this link: