2

I need to dynamically set some values to create/update records of a custom object.

The main idea is to create something like this:

MyCustomObject.fields["fieldName"].Value = "some value";

Does Apex have any way to do that?

1
  • 1
    Is it a custom SObject or an instance of a custom Apex Class?
    – Adrian Larson
    Jul 14 '17 at 15:42
5

Object is an ambiguous term in this context. If by custom object you mean SObject, then it is straightforward as you can use the put method inherited from the SObject class:

MyCustomObject__c record = new MyCustomObject__c();
record.put('MyCustomField__c', 'Some Value');
0
1

You can use the put method of the sObject class. This could look like this: customObj.put('fieldname', field value)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.