1

I would like to call someMethod1 and someMethod2 from myClass from a Trigger on update. How can I use type casting to call the two methods?

myInterfaceClass

public interface myInterfaceClass {
  void someMethod1();
  void someMethod2();
}

myClass class

public class myClass implements myInterfaceClass {
  public static void someMethod1() { /* code logic */ }
  public static void someMethod2() { /* code logic */ }  
}

Here is what i tried but not sure it is correct

myTrigger class

trigger myTrigger on Contact (after update) {
  Type myType = Type.forName('myClass');
  myType.someMethod1();
}
3

You need to cast your variable type. The class that implements that interface should be cast to that interface, so you can access its methods:

 IMyInterface instance = (IMyInterface) Type.forName('Myclass');
 instance.someMethod1();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.