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
sparkysparky 

collection of custom objects

I've created a class which will be instantiated multiple times in the trigger I'm working on, and I want to create a list or map of those custom objects.

In order to do that do I need to turn my class into an implementation of an interface?

That seems to be what the language reference is saying, but then on pg. 120 it says:

"Lists and maps can be used with classes and interfaces, in the same ways that lists and maps can be used with SObjects"

This is somewhat vague, but it seems to be hinting that perhaps there's a way to make a collection of instances of a standard class, as opposed to an interface-implementing class?  I could use some help grokking the whole "Classes and Collections" section on that pg.

If I do need to use an interface, does this add overhead to all of the apex code in my enviornment?  Since there's no equivalent of an import or include statement, I would assume that any class defined as an interface is included in every piece of code compiled?  Or does it only compile it in as needed?

Thanks much!
claudioclaudio
Matthew,

You don't need to use an interface to be able to put your objects in a collection, your class can be a regular public class.

Claudio