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
Avinash VellalaAvinash Vellala 

Update multiple object records dyanmically

I am trying to write an Apex class that could be run on a schedule. The aim is to iterate through objects and identify NULLs on a particular field and populate that field. So far I've written the below code but it is throwing the "Error: Compile Error: Variable does not exist: Auto_ID__c at line 16 column 56"
 
public class fixPersistentID {


List<String> objs = new List<String>{'ICP__c','Invoice_Number__c'};

        void populate_NULL_PID(){
        
                for(String s : objs){
                
                   String query = 'Select Auto_ID__c FROM '+ s +' WHERE Persistent_ID__c = null';
                   
                   List <sObject> sObj = database.query(query);
                   
                       for(sObject x : sObj){

                                x.Persistent_ID__c = x.Auto_ID__c;

                     }
                     
                   update x;
                
                
                }
                
               
        }


}



 
Maharajan CMaharajan C
Hi Avinash,

try the below changes inside the for loop.

for(sObject x : sObj){
     x.put('Persistent_ID__c', x.get('Auto_ID__c') );
}


Thanks,
Maharajan.C