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
Darryl SinghDarryl Singh 

Custom Object Extensions

Hi Everyone,

We can extend standard controllers and use these extensions in Visualforce pages, and that's great.  But we have batch Apex classes that need to be able to execute our own custom methods on some of our custom objects, so we would like to be able to extend custom object classes by adding our own custom methods without setting up dummy VF pages.

For example, we wish to add a custom method myMethod to the custom object MyCustomObject__c  so that we may use that method in a batch Apex class.  Something like:
 
MyCustomObject__c MyCO = new MyCustomObject__c();
MyCO.myMethod();

Anybody know how to do this?

hisrinuhisrinu

You can't extend an object however you can build a wrapper class which includes the custom object and add your custom methods

 

Here is an example

Darryl SinghDarryl Singh

Thanks, Srini.  Wrapper class will meet our requirements.