Pass function as parameter to a function in Apex
Feb 7, 2021
…well sortof …hear me out!
We create interface as above to perform dynamism in calling functions, and that’s all the boilerplate code that we need!!!
Next we implement our interface in our particular class and override our execute function with our required behavior.
In this case we print Id of passed sObject
Here we are printing Name and like wise… you get the point
But what if I want something else altogether like lets say print a given string.
Voila…
Lets use this…
I have my printer function that will conditionally print values one by one.