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

adding instance methods to Sobjects

Is it possible to (and if so how) to add apex methods to a custom Sobject? standard Sobject? Or do I need to create a child/wrapper class or utility class? Thanks, Dovid

can you please elaborate which apex methods are you talking about? Please search for "Apex sObject Methods" in the Apex developer guide and you will find a list of sObject methods

I am asking about creating my own custom methods on the sobject itself in order to do custom manipulation or processing of sobject member data (fields).

You can go for Controller Extension to customize the standard functionality..


Let me know if that answers your question.

no, not really. but thanks. What I mean is like this: When I create a plain old class in apex code I can create instance variables and methods to manipulate those variables. Now, when I create a new SObject via the browser or via meta-data, it creates a class blueprint to instantiate that new custom SObject, hence we can call new on it and use any of the methods in the SOject super class. What I want is access to that blueprint to add additional methods to manipulate the fields. This is irrespective of whether it's a VF controller, trigger, or POAO (plain old Apex object). But I get the feeling that is not possible and I would need to subclass the SOject or create static utility methods to perform manipulations. Unless anyone knows differently? Dovid

Since internal is not exposed by salesforce, this is not possible. You can just add some functionality to standard functionality as I said in my last post.