I have an Apex method that takes a list of SObjects, a source field name, and a destination fieldname. For each SObject in the list, it looks at the source field, does some work, and populates the destination field using the calculated value. The method signature looks like this:
public static void SyncCodes(list<SObject> objs, String SourceField, String DestField)
I can use this method with different SObjects that have slightly different field names for the same types of fields. Works well. Note that the method does no DML - it just reads a field (using .get()) and writes a field (using .put()).
But now I need to use this method to calculate values for an SObject that has no destination field. I just want to get the answers. I could refactor the code, but I'd like to find another solution.
What feels like the right answer is to create a wrapper object and pass that to the method. However, wrapper object usually means an (inner) Apex class, which is not an SObject. So the primary question: is it possible to write a method that accepts either an SObject or an instance of an Apex Class? What is the data type of the param? Is there an interface that SObject implements, which I can also implement in my class?
I should mention that I have a workaround: since the method does no DML, I can just use an existing SObject type that has source and destination fields as my wrapper class. Just create them in memory and discard when finished. But this got me wondering about passing generic instances of apex classes around, and interchanging them with SObjects.
Object, but I sure can't find the documentation. I'll play with that and see what works, but if you know of a doc link for
Object, please post it as an answer I can upvote :)