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
Force.comForce.com 

Set Account "fields" dynamically

Hi,

 

There is a picklist showing all the fields of Account. User will seleect one of the fields and enter any value to it. In the controller, I need to set that particulat field Account to the entered value. 

 

I am able to get the selected field and its value in String format as

String apiName = name__c;

String val = "Test";

 

But when I am trying to set the Account field as 

Account acc;

acc.apiName = val;

 

I am getting the following Compilation error:

Compile Error: Invalid field apiName for SObject Account 

 

I am not able to figure out its solution. If anyone has experienced such problem, please help.

 

Its urgent. 

 

Thanks,

Pragati

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

As you have the name and value combination for the field, you'll need to use dynamic DML (get/put syntax):

 

String apiName='name__c';
String val='test;l

Account acc;
acc.put(apiName, val);

 

All Answers

bob_buzzardbob_buzzard

As you have the name and value combination for the field, you'll need to use dynamic DML (get/put syntax):

 

String apiName='name__c';
String val='test;l

Account acc;
acc.put(apiName, val);

 

This was selected as the best answer
Force.comForce.com

Thanks a lot Bob. It helped :)