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?

4
  • Have you tried to use a Batch for this?
    – Patlatus
    Commented Mar 29, 2020 at 17:31
  • Strange, standard method works for me.
    – Patlatus
    Commented Mar 29, 2020 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
    Commented Mar 30, 2020 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
    Commented Mar 30, 2020 at 17:41

2 Answers 2

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.

5
  • 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
    Commented Mar 30, 2020 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
    Commented Mar 30, 2020 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
    Commented Mar 30, 2020 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
    Commented Apr 7, 2020 at 1:15
  • Ok, cool. So Salesforce has fixed internally something.
    – Patlatus
    Commented Apr 8, 2020 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);
 }
3
  • This is a pattern that you should avoid: you will hit 150 DML limit
    – kvor
    Commented Mar 30, 2020 at 17:06
  • 1
    @kvor actually p-p is right: Database.deleteImmediate method execution is not counted in 150 DML limit
    – Patlatus
    Commented Mar 30, 2020 at 17:42
  • @Patlatus My bad. You are both right. It does not count (just confirmed it).
    – kvor
    Commented Mar 30, 2020 at 19:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .