You need to sign in to do that
Don't have an account?
shrutiiiii
Pass class instance name by String
I'm working on creating a managed package. In my managed package, there is a global virtual class and a method defined. I installed the beta version of package to a test organization and created an another class which is inherited from the package class. In this class I overriden the method.
e.g. Package class:
global class ManagedPackageInheritance {
global virtual class VirtualClass {
global virtual void foo () {
System.debug('#Foo from Managed Package !');
}
}
}
Inherited apex class in test org:
global class PlayVirtualInheritance extends namespace.ManagedPackageInheritance.VirtualClass {
// override the virtual method
global override void foo() {
super.foo();
System.debug('#Foo from Target Org !');
}
}
So my question is, while calling the method 'foo', I want to pass the class instance name as a parameter. Something like this:
global class clsInvoke{
public void invokeFoo(String className) ///namespace.ManagedPackageInheritance.VirtualClass OR PlayVirtualInheritance
{
//here call method foo() from the either class depending on the class name passed
}
}
I think I need to use 'Type' class methods. But not sure how? I want to do this, because suppose the client/customer who has installed our package does not want the functionality provided by us, and they want to implement their own functionality. So the client will inherit our class and override the method. And then there is no need to modify the method invokation part.
Can anyone help me in this?
e.g. Package class:
global class ManagedPackageInheritance {
global virtual class VirtualClass {
global virtual void foo () {
System.debug('#Foo from Managed Package !');
}
}
}
Inherited apex class in test org:
global class PlayVirtualInheritance extends namespace.ManagedPackageInheritance.VirtualClass {
// override the virtual method
global override void foo() {
super.foo();
System.debug('#Foo from Target Org !');
}
}
So my question is, while calling the method 'foo', I want to pass the class instance name as a parameter. Something like this:
global class clsInvoke{
public void invokeFoo(String className) ///namespace.ManagedPackageInheritance.VirtualClass OR PlayVirtualInheritance
{
//here call method foo() from the either class depending on the class name passed
}
}
I think I need to use 'Type' class methods. But not sure how? I want to do this, because suppose the client/customer who has installed our package does not want the functionality provided by us, and they want to implement their own functionality. So the client will inherit our class and override the method. And then there is no need to modify the method invokation part.
Can anyone help me in this?
What do I do to invoke:
PlayVirtualInheritance obj = new PlayVirtualInheritance();
obj.foo();
Instead of this:
namespace.ManagedPackageInheritance.VirtualClass obj = new namespace.ManagedPackageInheritance.VirtualClass();
obj.foo();
Without changing the method calls? How do I pass obj instance name?
FYI : https://www.xgeek.net/salesforce/instantiating-a-apex-class-based-on-dynamic-string-name-with-type-class/