Skip to main content
deleted 3 characters in body
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

I recommend you use Data Loader for this task.

  1. Export the query you have already written
  2. Manipulate the CSV to set DisqualifiedReason__c and OwnerId to the proper values.
  3. 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

I recommend you use Data Loader for this task.

  1. Export the query you have already written
  2. Manipulate the CSV to set DisqualifiedReason__c and OwnerId to the proper values.
  3. 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.getQueryLocator 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

I recommend you use Data Loader for this task.

  1. Export the query you have already written
  2. Manipulate the CSV to set DisqualifiedReason__c and OwnerId to the proper values.
  3. 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.QueryLocator 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
added 1209 characters in body
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

I recommend you use Data Loader for this task.

  1. Export the query you have already written
  2. Manipulate the CSV to set DisqualifiedReason__c and OwnerId to the proper values.
  3. 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.getQueryLocator 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

I recommend you use Data Loader for this task.

  1. Export the query you have already written
  2. Manipulate the CSV to set DisqualifiedReason__c and OwnerId to the proper values.
  3. 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.

I recommend you use Data Loader for this task.

  1. Export the query you have already written
  2. Manipulate the CSV to set DisqualifiedReason__c and OwnerId to the proper values.
  3. 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.getQueryLocator 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
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

I recommend you use Data Loader for this task.

  1. Export the query you have already written
  2. Manipulate the CSV to set DisqualifiedReason__c and OwnerId to the proper values.
  3. 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.