function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KrisztianKrisztian 

Set Object's fields by string parameters.

Hi,
I process XML files. The XML has special structura so I create a mapper. Example: Account.ID -> Account.ExternalId__c
I want to set the account's field via string parameters. How can I create this procedure?

void SetByParams(Account acc, String field, String value){
   //abstract: acc.'field' = value;
}

Best Answer chosen by Krisztian
hitesh90hitesh90
Hi Koszi,

you have to use .Put method for dynamically assign field and value.
see below example,

Example:
void SetByParams(Account acc, String field, String value){
       //abstract: acc.'field' = value;
       acc.put(field,value);
    }

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
Email :- hiteshpatel.aspl@gmail.com
My Blog:- http://mrjavascript.blogspot.in/

All Answers

hitesh90hitesh90
Hi Koszi,

you have to use .Put method for dynamically assign field and value.
see below example,

Example:
void SetByParams(Account acc, String field, String value){
       //abstract: acc.'field' = value;
       acc.put(field,value);
    }

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
Email :- hiteshpatel.aspl@gmail.com
My Blog:- http://mrjavascript.blogspot.in/
This was selected as the best answer
KrisztianKrisztian
Thanks, it works!