I have a relatively large Map<String, String>
which is basically a key/value map of sobject field names and their values. Obviously, all the values are strings, but fields are not (there are currencies, dates and so on). I need a simple way to be able to assign them all without having to make a check on each field individually.
I can't use simple
sobject.put(fieldname, value);
because there is type mismatch on most lines.
What I did think of is to use JSON deserialize, because then casting gets done implicitly (I think - it seems to work). So the idea would be to either compile a valid JSON string manually or maybe make a dummy object that has all the fields named the same, but of type String. Then I could just do
objectInstance.put(fieldname, value);
String jsonSerialized = JSON.serialize(objectInstance);
SObject sobj = (SObject)JSON.deserialize(jsonSerialized, SObject.class);
However, this firstly seems as a hassle and secondly it seems complicated and as if there's a simpler solution.
Can you offer another approach?