4

We have a Sandbox environment with storage limit 2 GB, while alone Order_item__c storage amount is 1.8 GB.

We are trying to delete the record using the filter Year<=2013 from Order_item__c module. How do we deal with mass deletion of records with based on year filter using workbench?

1

You can write a one time batch and execute it using anonymous window in dev console.

1
  • Can you provide an example to show how this would be done? The asnwer isn't much use on it's own!
    – Matt Lacey
    Apr 4 '16 at 23:17
1

Not sure if Year is a custom field. You will need to run this script (or a similiar script) in the Developer Console. Create a list to gather the records you want to delete, then delete that list.

//Create List of Desired Records to Delete
List<Order_item__c> delLst = [SELECT id FROM Order_item__c WHERE Year__c <= 2013 LIMIT 50000] ;
//Delete List
delete delLst;
14
  • Problem is we just had <10k records captured in <=2013 but 879235 records fall in 2016 that means 1.7 GB still to be deleted. But we want to keep this year records. Question is i am bit confused with process of what to delete in this case for currrent Year
    – Sylphes
    Apr 1 '16 at 15:32
  • Change the script to "List<Order_item__c> delLst = [SELECT id FROM Order_item__c WHERE Year__c != 2016 LIMIT 50000] ; delete delLst;". You will now only delete records where their year is not equal to 2016. I do not full understand your comment. Why are you using the sandbox to stores these record? Just export them out and save them for future use. Apr 1 '16 at 15:37
  • Ok I am going to make try on it
    – Sylphes
    Apr 1 '16 at 15:38
  • 1
    Let us continue this discussion in chat.
    – Sylphes
    Apr 1 '16 at 16:00
  • 1
    I sorry I cannot use chat right now. You should have all the tools you need to solve this problem. Deleting records is well documented. Make sure you are in the right sandbox (your sandbox may very well be empty if it is a dev sandbox). Apr 1 '16 at 16:08
1

You might probably want to refresh your existing sandbox and use Sandbox templates:

Sandbox templates allow you to pick specific objects and data to copy to your Full or Partial Copy sandbox to control the size and content of each sandbox. Sandbox templates are only available for use with Full or Partial Copy sandboxes.

When you create a sandbox template, you select the object data (standard and custom) to copy during the creation or refresh of a sandbox.

If you don't want to refresh the sandbox now, you could go with one of the below options:

  1. Run a one-time batch job to delete the records you want. This will require Apex coding.

  2. Run a query in the data loader to fetch all the records you wish to delete and then perform the delete operation using the data loader.

1

You can operate on the results of a SOQL query. Would be simple enough to query using SELECT Id FROM Order_item__c WHERE Year<=2013. Be certain to use the proper field names of course.

Edit

Its been to run that as anonymous APEX using something like

DateTime MyDT = DateTime.newInstance(2012, 31, 12, 24, 59, 59);
list<Order_item__c>mylist=[SELECT ID FROM Order_item__c WHERE CreatedDate <=: MyDT  Limit 10000] ;   
Delete mylist;
7
  • We give our try on soql :SELECT Id FROM Order_Item__c WHERE CALENDAR_YEAR(CreatedDate) <= 2013 then WE want to delete this ID's FROM delete option of workbench.
    – Sylphes
    Apr 1 '16 at 15:22
  • See my edited answer with suggestions.
    – crmprogdev
    Apr 1 '16 at 16:10
  • @crmprogev We have deleted the the data<=2015 . we have to take care of current Year data that is 2016 only it constitute 1.7 GB alone. We have constraint that full sandbox should be copy of production. and it is mandatory to keep current Year records. We are finding the way to deal with this situation. Your time is always valuable for me.Thanks.
    – Sylphes
    Apr 1 '16 at 17:05
  • isn't the DML limit on records per transaction 10,000?
    – cropredy
    Apr 1 '16 at 23:32
  • @cropredy. Yes, indeed it is. The limit on records returned in a SOQL query is 50k, thus the reason I specified that limit. If more than 10k are returned, they could use a for loop to delete the records in 10k chunks. They can't query more than 50k records & delete at the same time unless they write a SOQL for loop. In that situation, I believe it would occur in batches of 200 records.
    – crmprogdev
    Apr 3 '16 at 13:08

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.