You need to sign in to do that
Don't have an account?

updating a field in list of sObject
Hi ,
i have a list of sobject as
List<sObject> lstSObject = new List<sObject>();
i want to update a field test__c = 'abc' for all the records in this list of sObject.
i tried something like
i have a list of sobject as
List<sObject> lstSObject = new List<sObject>();
i want to update a field test__c = 'abc' for all the records in this list of sObject.
i tried something like
for(SObject so : lstSObject){ so.test__c = so.test__c + 1; } update lstSobject;
But it throw me the error saying could not identify variable test__c.
Can anyone please give me a snippet how to update a specific field of list of sObjects?
You cannot directly update a field with an sobject type. You have to first cast that sobject to the type of object on which your custom field is.
The code will look something like this: