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?
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 communityObject 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');
You can use the put method of the sObject class. This could look like this: customObj.put('fieldname', field value)
SObject
or an instance of a customApex Class
?