You need to sign in to do that
Don't have an account?
Avinash 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; } } }
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