SObject model extension classes - Ideas - Salesforce Trailblazer Community
Trailblazer Community

All Ideas

Idea Details

Post an Idea
340  Points
Idea has been posted. Give it an upvote or downvote.

SObject model extension classes

Accounts & Contacts

SObject classes in are essentially Model classes in an MVC pattern, and they're very powerful in this regard, but they are mostly declaratively defined.

I would like to have a way to use Apex classes as models that act like mixins, extending the functionality of underlying SObject classes.  This would make it easier to cleanly isolate business logic in a model layer where it belongs, and leave Visualforce views and controller classes blissfully uncoupled from those details.

Perhaps, this could be implemented by adding a virtual Extension class to each SObject class that could be used as the subclass for custom extensions...

  class MyContactExtension extends Contact.Extension {

      public MyContactExtension(Contact contact) {

      // ...

  class MyController {
      public MyContactExtension contact {get ; private set ;}

      public MyController() {
          Contact c = [select ... from Contact where ...];
          contact = new MyContactExtension(c);


Ideally, such extensions would be able to expose new attributes that behave like real SObject fields in that they can be used as apex:inputField values in Visualforce forms, specify label text, etc.  It would also be nice to be able to override the extended behavior of existing underlying fields such as by exposing a normally read/write field as read-only or a normally optional field as required.

Merge Idea · Flag

  • Upvotes
  • Downvotes



from AppExchange


Help us to keep IdeaExchange clean by pointing out overlapping ideas. We'll investigate your suggestion and merge the ideas if it makes sense.



Thanks for your merge suggestion. We will review it shortly and merge the ideas if applicable.

Salesforce takes abuse situations very seriously. Examples of abuse include but are not limited to posting of offensive language or fraudulent statements. To help us process your request as quickly as possible, please fill out the form below describing the situation. For privacy and security reasons, the final outcome of an abuse case may not be revealed to the person who reported it.


Thank you for your feedback. We take abuse seriously and will investigate this issue and take appropriate action.