+ Start a Discussion

How to make reflection programming in Salesforce

I want to know how you could write a bit of code to do true reflection programming in Salesforce

So say you have a piece of data which has the name of functions and the apex code will take this and run the function you have entered, so if a new function is deployed to Salesforce you dont need to change this class with another if statement and will still be able to run the new function
You don't have reflection in Apex unfortunately, so you can't dynamically generate the name of a function and execute it. The best that you can do is to instantiate an interface from a type and execute known methods from the interface.  That stops you being tied into specific implementations of the interface, but your code still needs to know the names of the methods that it will invoke.