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

Writing Class to wrapper by custom object

Hi There,


This is a real noob quesion so apologies in advance.


I have created a custom object called TMDR_PackageEntry__c and in addition to all the build in methods like save() etc I would like to have a few validation methods of my own. How can I write a class that extends the default class that must exist around this new object?


I'm assuming there is a way to do this to avoid having to rewrite all the getter and setter methods etc.








Depends on what you'd like to do but you don't have access to the class that wraps the object. You can however create 'extensions' but then you'll also need to write your own Visualforce pages.


Have a look at this doc:




Hi Wez,


Maybe I've misunderstood or maybe I've not explained myself very well.


So I've got a bunch of custom objects that are all interdependent as they all support a single area of functionality.


I've then got a bunch of VF pages and a single controller that form the wizard for managing these.


There must be some sensible way to manage the interaction between the objects.


For a more concrete example:


Say I have custom objects for:


- Car Make

- Car Model

- Car Part


With their parent -> child relationships set up as you'd expect.


I have a controller called 'Car Part Wizard' that firstly loads up a list of 'Car Make's , and the user can add/edit/delete these and add 'Car Model's to each one.


So I have written a class (in true MVC style) called 'Car Make' that I'd like to be an extension of the 'Car Make' Object. I'm assuming that there is currently an invisible class around the 'Car Make' object that has getter, setter methods for fields and things like save etc. Rather than rewrite that myself in my class, I'd like to extend this invisible class.


The idea is that when the controller loads up a list of 'Car Makes' it is actually grabbing a list of instances of my class not my object. The controller can then access fields directly etc.


Moving on from that, each instance of my 'Car make' Class, once instantiated, would load up a list of it's 'Car Models' which would again me a list of instances of my class and not my object.


Does that all make sense?





Perfect sense. Unfortunately you don't have access to the object "class" like you might in Java (using Hibernate or JPA). Instead you'd have to wrap your objects in classes of your own design that might just abstract the get/set methods and any standard-ish functionality. You could virtualise these classes and extend them for specific instances of models, parts etc. It makes for some superfluous coding but it's a restriction of the technology.


From the sounds of things you might also benefit from developing a set of "wrapper" classes that conform to the Factory Pattern. You seem to understand the principles of development (your problem is well phrased and speak of experience) so I apologise if I'm telling you the obvious.