+ Start a Discussion
goabhigogoabhigo 

Deleting records from Staging object

Is there any best practice to delete the records from Staging objects (which is uploaded daily through Jitterbit)? The data limit has crossed 2000%. Immediate solution would be to delete the records that are processed then schedule a batch class which will run, say weekly, and deletes the success records.


In simple terms how this works is: Staging Account object will be populated daily, the user selects bulk records and clicks on "Process", the controller runs and inserts/updates the Account.

 

Any suggestions?

bob_buzzardbob_buzzard

Is there any reason why the controller couldn't fire an @future call to delete the staging records?  You could pass it the list of ids of records that were processed and tidy up those.

goabhigogoabhigo

Ahh that's another great option. But when does @future run?

bob_buzzardbob_buzzard

It gets queued for running as soon as there is resource to support it. 

 

Another way could be to use the browser - so refresh the page to indicate to the user that the accounts have been inserted, then execute an actionfunction to hit a delete method in the controller.  It is a little fragile though, as the user could close the browser and stop the second submission.

GunnarGunnar

I had the same exact issue, moving from a temp table to a permanent table(object).

 

 

Look at  Database.SaveResult

 

You'll do a Database.Insert (MyList, false);            (instead of insert MyList)

You now have a list of ID's that made it into the table.

You'll need some common key between your QUEUE and the permanant table, then do a SOQL using the IN keyword to get the records in the queue.

With those, you can delete from the queue.

 

I can't spell out all the code, but this will point you in the right direction.