0

Sorry, I don't know if this is a proper context to make this question, but I don't know where to make this question.

I write here because I immagine that a lot for today apex programmers has been java programmers.

I appreciate the feature of the SObjcet Class, where I can use methods as get/put for the fields of a SObject.

For SOBJECTS I can do things like:

Account acc = new account();
Acc.put('name',xxx);

The peculiarity is not to use a put method, but the aspect that the method is scalable as the database change, if i add a field, the put method works and is adapted to manage also the new fields. Looks like the method changes automatically with the database. I would reproduce a similar approach in java for a Database like MySQL o similar, the question is for a general OOP language and its interaction with a database.

Can you please suggest me any pattern or approach to reproduce similar behaviour?

2
  • 2
    This is not on topic here, but what you want, I think, is to use a HashMap. However, this sounds like a pretty bad idea. You should consider looking into ORM frameworks like Hibernate. Mar 23, 2016 at 21:21
  • @CharlesKoppelman Yes i know that is not on topic, but i didn't know how to make the question out of the community, where the others don't know Salesforce and its peculiarities. Thanks for your suggestion, I will to take a look on the framework. I don't understand why you are saying that is not a good idea. The SObject class simplify the life to me, and all the code is transparent to the changes of the database... but maybe I'm just newbie to java :)
    – Klodj_Meta
    Mar 23, 2016 at 21:29

1 Answer 1

1

I also think this is off-topic, and could be moved to the general StackOverflow. However, have you tried using reflection? The reflection library in Java allows you to reference methods/properties by their names contained in a string.

A quick googling shows this: https://stackoverflow.com/questions/14374878/using-reflection-to-set-an-object-property

You must log in to answer this question.

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