2

We have a managed package. In the managed package, we have a button in the application. When the user clicks on the button, we want the customer's specific logic to be executed (which could potentially be written in an apex class). The apex class could return us to a true/false value and based on that we can make further decisions on what would happened in the managed package.

Can this be achieved in salesforce? What is the best way to implement this functionality? Can we ship an interface that customer can implement which will be callable from the button.

  • I would think as long as the interface is global you should have no problem. – Adrian Larson Sep 1 '16 at 21:14
4

As well as the global interface, you need to provide a way to register the name of the customer's class that implements that interface e.g. in a custom setting.

Your code can then look like this

String className = ...;
YourInterface instance = (YourInterface) Type.forName(className).newInstance();
Boolean b = instance.getResult();

to create the instance and so be able to invoke it.

This pattern is illustrated in Type Class documentation. Read that documentation carefully because the namespace handling is a bit awkward.

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.