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

set of Contacts not allowed??

In the general declarations for a class I'm working on, I have:

 private set<Contact> RelatedCons = new set<Contact> ();

this gives me an error of:

    "Compilation error: Set of SOBJECT:Contact not allowed" when I attempt to save it in eclipse.

What's going on?
Venkat PolisettVenkat Polisett
You cannot store SObjects in a Set.

A set is an unordered collection of primitives that do not contain any duplicate elements.

Venkat Polisetti

Aha, right, missed that.

I could've sworn I had used sets of sobjects in the past, but looking back I see now it was only id's.



Well, the current version of the Apex Developer Guide says:  

set is an unordered collection of primitives or sObjects that do not contain any duplicate elements. For example, the following table represents a set of String, that uses city names:

...and the example shows a set of Accounts...

Venkat PolisettVenkat Polisett

Currently Sobjects are allowed in Sets but not when we replied to the original message. Read the time of the original post (2007). A lot has changed since then for the better.


Hope this helps.