I recommend you use Data Loader
for this task.
- Export the query you have already written
- Manipulate the CSV to set
DisqualifiedReason__c
andOwnerId
to the proper values. - Import the manipulated CSV
You don't need any Apex if you approach the task this way. You can also break the query out into a few discrete chunks to simplify the SOQL.
If you still want this logic to run daily and expect large volumes, you should use a batch to chunk the records.
public with sharing class MyBatch implements Database.Batchable<SObject>, Schedulable
{
public void execute(SchedulableContext context) { Database.executeBatch(this); }
public Database.getQueryLocatorQueryLocator start(Datbase.BatchableContext context)
{
return Database.getQueryLocator([/*current query*/]);
}
public void execute(Database.BatchableContext context, List<Account> records)
{
for(Account record: records){
record.DisqualifiedReason__c = 'No response';
record.OwnerId = '000000000000000';
}
update records;
}
public void finish(Database.BatchableContext context)
{
// optional implementation
}
}
If you are still having trouble with timeouts, you can reduce the batch size in your execute(SchedulableContext)
method. You could go as low as one record per chunk, though this size would cause your batch to run quite slowly.
Database.executeBatch(this, 1); // default is 200