1

I've searched through various questions here, and via Google, and see nothing other than Apex possibilities, which are far too slow.

Anyone know of a creative way to TRUNCATE the data in a custom object which is part of a managed package (Exact Target in this case)?

I can do 10 million records a day via the Bulk API.

I have Batch Apex Code that eats away at it slowly (would take weeks, there are 80 million records or more).

We need the object EMPTY (or 1 record, or...) inside our Full Sandbox. You can't do anything when populating or refreshing the sandbox to accomplish this, to my knowledge and exploration.

Help? I LIVE outside the box, so I'm all for anything queer or odd. We are in talks with ET to see if they will give us some kind of deployment update we could send to the Sandbox, possibly GIVING US access to the object, so we could POSSIBLY truncate it. Geez.

Thanks!

2

As a creative solution, I would suggest a batchable class. However, I'll one-up this by making it able to delete 10,000,000,000 rows in much less than 24 hours (assuming, of course, no triggers are at play, which will affect the speed and potentially cause errors).

public class TruncateBatch implements Database.batchable<integer>, Iterator<integer>, iterable<integer> {
    integer counter = 0;
    public iterator<integer> iterator() {
        return this;
    }
    public boolean hasnext() {
        return counter<10000; // multiplier factor
    }
    public integer next() {
        return counter++;
    }
    public iterable<integer> start(database.batchablecontext context) {
        return this;
    }
    public void execute(database.batchablecontext context, integer[] scope) {
        // maximum DML per transaction
        delete [select id from object__c order by id limit 10000];
    }
    public void finish(Database.batchablecontext context) {
        // pull out the last 10 records
        database.undelete([select id from object__c order by id desc limit 10 all rows]);
    }
}

Run this with Database.executeBatch(new TruncateBatch(), 1) to give yourself 10,000 counts of 10,000 rows, which should run in a couple of hours, and delete up to 10,000,000,000 rows of data.

  • brilliant ; (1) I never thought of putting the iterable and iterators in the batch class as I had blindly followed the examples in the apex doc and have more classes than I really need. (2) Do you want to also erase the deleted objs from recycle bin as to plausibly make room for normal, other user obj deletes and their possible recovery? – cropredy Feb 10 '15 at 2:35
  • Why bother to undelete at the end? – Adrian Larson Feb 10 '15 at 2:42
  • @AdrianLarson They wanted a handful left over afterwards. Since a batch could have an even multiple of 10k, just pluck a couple back out afterwards. And, you could use emptyRecycleBin, but remember that'll cut the DML rows by half, so the iterations may need to be adjusted (and the limit, as well). – sfdcfox Feb 10 '15 at 3:44
1

You may be able to create a batchable class that can mass delete these objects. @sfdcfox posted an example a couple days ago at:

Mass Deletion Of (most) Records (in Sandbox) (100 million+)

Also look at the comment from @Adrian Larson to empty the recycle bin as well.

  • The batchable script, which can be run 5 times max concurrently, is able to do appx 8-10 mil records a day, assuming it does not fail all day. That combined with Bulk API calls allowing me 10 mil deletions a day, has me down to about 4 days of manual labor. – AMM Feb 9 '15 at 18:04
  • I was under the impression that it could easily process 50 millions records. salesforce.com/us/developer/docs/workbook_chatter/Content/… – TC Sutton Feb 9 '15 at 18:24
  • Hmm. All I can say is, with Bulk API turned on and 2000 selected, it's allowing me about 10 mil records before telling me to shove off for 24 hours. :-/ – AMM Feb 9 '15 at 20:26
  • The Bulk API limit on a batch size can contain a maximum of 10,000 records. I think you are limiting yourself to 1/5th of what the Bulk API is capable of. developer.salesforce.com/docs/… – TC Sutton Feb 10 '15 at 0:22
  • There's a bulk api call limit on your org, you can avoid this by increasing your batch size to 10k as stated, and you could ask support to temporarely increase the api call limit. If you're able to query/delete subsets of data you should be able to run data loaders in parallel. – Samuel De Rycke Feb 10 '15 at 7:17

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.