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.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityAll 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));
}
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.