+ Start a Discussion

How to do reflection 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
True reflection, as understood by rubyists like myself isn't *really* an option on the platform. I just wrote a blog article, however about how you can effectively create an "eval()" method on the platform using the tooling api. However, it's not quick, burns through api calls and is in general not what you're looking for. 

That said, here's the article: 
http://codefriar.com/2014/10/30/eval-in-apex-secure-dynamic-code-evaluation-on-the-salesforce1-platform/ (http://codefriar.com/2014/10/30/eval-in-apex-secure-dynamic-code-evaluation-on-the-salesforce1-platform/" target="_blank)
Tyler Mowbrey 1Tyler Mowbrey 1
As Kevin has noted reflection is not really an option. In addition to his resource, here is another you can review: http://www.sundoginteractive.com/sunblog/posts/using-reflection-with-salesforce-custom-apex-classes-sort-of.
Stephen HernandezStephen Hernandez
"eval()" method on the platform took me a lot of time and nerves I wouldn't recommend anyone except maybe experts applying it. Reflection doesn't work here, thank you Tyler for a great resource, as I was considering using http://writemyessaytoday.net/ for some help on related issues.