3

Known Issue for not being able to deletg Big Objects with database.deleteImmediate still open. This is the only method mentioned in docs to do this. Workaround to delete 1 X 1 is a joke.

Any other straightforward methods to delete multiple records (10000 at a time) in a Big Object until the KI is fixed, without dropping and recreating the object since that can cause dependency issues?

  • Have you tried to use a Batch for this? – Patlatus Mar 29 at 17:31
  • Strange, standard method works for me. – Patlatus Mar 29 at 18:05
  • I think it is related to the Index. We experience the same issue. One of our indexed fields is on descending order. @Patlatus do you have any indexed field in descending order? – kvor Mar 30 at 17:08
  • @kvor, yes, I have created an index including two fields: one ascending and one descending and I cannot reproduce this issue – Patlatus Mar 30 at 17:41
0

This seems strange, but in fact I cannot reproduce your issue.

However, if I were able to reproduce this issue, I would solve this by using a Batch.

public class DeleteBatch implements Database.Batchable<SObject>, Database.Stateful {
    public final String Query;

    public DeleteBatch ( String q ) {
        Query = q;
    }

    public Iterable<SObject> start( Database.BatchableContext bc ) {
        return Database.query(query);
    }

    public void execute( Database.BatchableContext bc, SObject[] scope ) {
        Database.deleteImmediate(scope);
    }

    public void finish( Database.BatchableContext bc ) {

    }

}

Database.executeBatch(new DeleteBatch('select Son__c, Daughter__c from Big_Mommy__b'));

However, for me even simple statement

Database.deleteImmediate([select Son__c, Daughter__c from Big_Mommy__b]);

executes successfully, so I am unable to verify if batch works for you. But in batch you can set batch size for example

Database.executeBatch(new DeleteBatch('select Son__c, Daughter__c from Big_Mommy__b'), 1);

to execute one record at a time.

Or you could modify my execute statement

public void execute( Database.BatchableContext bc, SObject[] scope ) {
for (SObject record:scope)
            Database.deleteImmediate(record);
        }

I think at least one of these options should work for you.

| improve this answer | |
  • Using Database.executeBatch(new DeleteBatch('select Son__c, Daughter__c from Big_Mommy__b'), 1); in a big object, could lead to Asynchronous Apex method execution limit (250k per 24h). – kvor Mar 30 at 17:05
  • I think CPU time limit might be exhausted first. However, the task here is to provide a way to delete big object records – Patlatus Mar 30 at 17:38
  • How CPU time limit will happen will happen? Limits will reset after each execution of execute(). One possible limit to reach is the 250k batch apex execution if you want to delete couple hundred thousand records (if scope == 1). – kvor Mar 30 at 19:45
  • It looks like the solution is that even though the Known Issue is still open, the original method, outlined by Salesforce and put here using Database.deleteImmediate now works again. – ddeve Apr 7 at 1:15
  • Ok, cool. So Salesforce has fixed internally something. – Patlatus Apr 8 at 12:22
0

If you are forced to process one record at a time, then you should just iterate over collection since there are no Gobernor Limit on execution of Database.deleteImmediate method

 for (SObject record:[select Son__c, Daughter__c from Big_Mommy__b)
        Database.deleteImmediate(record);
 }
| improve this answer | |
  • This is a pattern that you should avoid: you will hit 150 DML limit – kvor Mar 30 at 17:06
  • 1
    @kvor actually p-p is right: Database.deleteImmediate method execution is not counted in 150 DML limit – Patlatus Mar 30 at 17:42
  • @Patlatus My bad. You are both right. It does not count (just confirmed it). – kvor Mar 30 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.