I have a Map<String,String> containing <field API Name, field value>

Is there a way to insert them into an SObject that contains those field names exactly?

My SObject has hundreds of fields and I only want to insert those I have in the map.

1 Answer 1


All SObjects offer these methods that include a put by field API name method so the values can be transferred like this:

Map<String, String> m = ...;    // Could also be Map<String, Object>
SObject sob = ...;

for (String f : m.keySet()) {
    sob.put(f, m.get(f));
  • can i also dynamically check the type of field and convert my value to that type? @Kieth C
    – Shyam Raju
    Commented Mar 19, 2017 at 22:12
  • would making my map<String,Object> solve that problem for me?
    – Shyam Raju
    Commented Mar 19, 2017 at 22:13
  • 1
    Using Map<String, Object> is a good way to go as it lets you insert values of type String, Decimal, Boolean etc with the type maintained when the values are put into the SObject.
    – Keith C
    Commented Mar 19, 2017 at 22:18

You must log in to answer this question.

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