You need to sign in to do that
Don't have an account?

Can you extend a managed package's virtual Apex class?
Hey,
I will be finding this out for myself in the next little while, but meanwhile: Does anybody know whether the following is possible?
Say we have a managed package, with NS prefix 'XXX' and the following class:
We have this package deployed on an org, and now we want to do the following:
Is this legal? Can you extend a virtual base class, if that class is sitting inside a managed package? Can you even include virtual classes within a managed package, for that matter?
I will be finding this out for myself in the next little while, but meanwhile: Does anybody know whether the following is possible?
Say we have a managed package, with NS prefix 'XXX' and the following class:
global virtual class baseClass { WebService String baseString; public baseClass () { baseString = 'bsaeClass instantiated'; } }
We have this package deployed on an org, and now we want to do the following:
global class myClass extends XXX.baseClass { WebService String myString; public myClass () { super (); // --- not sure if this is necessary --- myString = 'myClass instantiated'; } }
philbo,
I'm curious, how did you create your package containing global virtual classes? I cannot create global virtual classes because I'm working in a Developer Edition org. This is an annoying limitation, since I do my development and packaging in a DE org. Did you create your global virtual classes within a Enterprise Edition sandbox and then do you packaging from the sandbox?
I would like to know the answer to this as well. philbo, did you ever figure this out?
Or could someone at SF set us straight?
BTW, for me the base class could be public, doesn't need to be global for my purposes.
Thanks much!
Trying to do this now and it does not appear to be working
This worked for me, this post explains all in detail : http://www.tgerm.com/2011/09/extend-managed-package-virtual-class.html
One issue that i faced that you noted in your blog was that "You cannot add a method to an abstract or virtual class after the class has been uploaded in a Managed - Released package version."
This was the very first problem that we faced, as of course, the first release missed things and we wanted to change the interface. We were going to move away from a global abstract class, but found that you could add to them provided the added methods where also virtual.
ie the following can be added:-
whereas a new method that isn't virtual can't be added and you get an error
From - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_manpkgs_package_versions.htm
"You cannot override a public or protected virtual method of a global class of an installed managed package"
so for the question, if you want to override a method from a manage package, the method must have the "global" access modifier. It is not enough being only virtual neither public.