Slaesforce FAQ

how to capture string in a field salesforce apex

by Astrid Ritchie Published 2 years ago Updated 2 years ago

Prelude

I have found countless ways to get the value of an sObjectField using a variable. E.g.,

What I've Tried

a.n = 'New Account Name'; // Results in "Variable does not exist: n" error.

Use Case

In a test data factory class I was wanting to iterate a map that has field names and values (where the field names could be different every time) and then create an object with those field names and values. If I can't use a variable to set a field name, I'm going to have to go through and check every possible field name.

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9