Delete Function

Posted by jsniemi79 on 21-Oct-2014 08:26

I have an object that I need to delete the records nightly and then re-import.  I am using a data maintenance batdch job to run the delete record trigger.  My issue is it is taking a really long time to run through the records.  I had a couple days in a row where the delete failed due to a timeout setting in shared properties.  Now I have about 3 times as many records in that object as I should and it is overstating the data.  

If I try to manually kick off the batch job, my browser hangs for 30-40 minutes before it says it was initiated and then it doesn't appear to be deleting any of the records.

This is the code I have inside the batch job.

Is there a better way to do this?  Even when this was working early last week, it was taking a long time to process through the records.  

All Replies

Posted by Gian Torralba on 21-Oct-2014 10:47

Hello,

May I know the average number of records being deleted? Are there also "after delete" triggers running?

Thank you,
Gian

Posted by jsniemi79 on 21-Oct-2014 10:50

Nightly this should be around 55K records being deleted.  That number should grow, but shouldn't be significantly higher than what it is now.  Because of the failed batch, right now, there are 189K records that need to be removed.

There are no after delete triggers setup on this object.

Posted by Gian Torralba on 21-Oct-2014 10:55

Hello,

Let me find another way to do this. The way you are using it now is that it iterates thru all records and use the delete API to delete single record meaning on the 55k records, it runs 55k delete API triggers.

I'll let you know if I find anything.

Thank you,
Gian

Posted by Gian Torralba on 21-Oct-2014 11:09

Hello,

Also, please check if there are any orphan control record for your object because the object might also delete other related record which slows the deletion process.

Thank you,
Gian

Posted by jsniemi79 on 21-Oct-2014 11:16

Deleting one of these records will not delete another.  There are a couple relationships and deleting the other records in the relationship will delete these, but not vice-versa.

Posted by Gian Torralba on 21-Oct-2014 11:22

Hello,

Thank you for the information you provided. Hmm.. It seems that this is the only way to delete all records using a batch job. I'll try to replicate this on my end and check the performance of the deletion process.

I'll let you know if I find anything else.

Thank you,
Gian

Posted by Gian Torralba on 28-Oct-2014 10:40

Hello,

After the process was "initiated" does it display anything in the system jobs section in the administration page? When you say last week, how long does it take to delete those records?

Thank you,
Gian

Posted by jsniemi79 on 28-Oct-2014 12:31

It doesn't say anything in the logs.  I am unsure the exact time it took to complete. I had to manually run the batch job multiple times before it finished deleting all the records.  It seemed to work for a while, but then would just stop like it had a timeout built in.

Posted by Gian Torralba on 29-Oct-2014 15:26

Hello,

It should run automatically on schedule though. Can you confirm this that the batch job is running? I don't see any problems with it deleting records if there are no triggers or orphan control in that object and even though it does time out, it should at least delete some records.

Let me know how it goes,

Thank you,
Gian

Posted by jsniemi79 on 29-Oct-2014 15:28

Yes, it does run nightly, but it can't get all the records done.  Therefore, it is gradually increasing the number of records daily and is overstating the values, rendering the data useless.

Posted by Gian Torralba on 29-Oct-2014 16:10

Hello,

Please wait while I test this on my end. I will email you to get more information about this.

Thank you,
Gian

Posted by Gian Torralba on 10-Nov-2014 15:31

Hello,

Can you test this by creating a clone of the object and then run a manual batch job just to see if the performance is slow? Please test this while there are no other processes running in the system jobs. I just did a test on a newly created object and the deletion process only took minutes.

Thank you,
Gian

This thread is closed