I would create a generic method which can take in input a generic object (not only an SObject)...

For example would create a method like:

public static output MyMethod(Object inputmessage, String Objpamaeter){
    inputmessage.put(Objpamaeter, 'xx');
    output xx= new outputValidation();
    return xx;

where output is an object with string parameteres, while inputmessage is an custom apex object or an SObject... If an so large generalization is not possible, what solution can be taken to prevent the fragmentation of the architecture?

thanks in advance...


1 Answer 1


I don't think you could make such a method with the current reflection support in Apex.

I'd suggest creating an interface that all input classes implement. Then you could just deal with them via that common interface. E.g.

public interface Validatable {
    bool isValid();

The standard sObjects won't implement this interface, so you might need to wrap them in a wrapper class.

  • Thnk! it has been useful :D As a workAround, I created a validation system, creating a map of the object like Map<String,Object> where the object is a standard sfdc object (string, Date, DateTime ecc...). After this I create a generic vadidator class which get in input a Map instead of a generic object. I hope that what I wrote is clear :D
    – Klodj_Meta
    May 21, 2013 at 16:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .