3

My organization does monthly deployments from our sandbox to production that include bug fixes and enhancements. When we deploy to production, we do testing to make sure that everything is working as expected and often create lots of test records in the process.

We want to make sure to delete any records created, so I was wondering if there'a a way to query our entire system to find any records that were created in the past "x" amount of hours. Any ideas?

Thanks, Rochelle

3

Yes you can query data to find records created at a certain date/time.

You can also query data to find records created by a specific User.

Using a combination of Date/Time and User queries you can gather the data the was created during your production checkout and delete them.

Tactically you can execute this a few ways.

  1. Using Data Loader or a ETL Tool to extract the data with a SOQL query in this format:

SELECT Id FROM Account WHERE CreatedDate > 2005-10-08T01:02:03Z

http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_soql_select_dateformats.htm

Make sure you take into account timezones, etc when you do your query.

You will have to do multiple queries against the different objects in your schema. You won't be able to do one single query against the whole schema, you will have to do multiples against the different objects.

1.A Perform Delete on the extracts with Data Loader.


  1. Create Reports in SFDC for this data and delete the records Manually or Export details to Spreadsheet that is consumed by Data Loader.
2

You can run a code like this in execute anonymous. This code deletes accounts created in the past 30 hours:

Datetime d = datetime.now().addhours(-30);
List<Account> accounts = [SELECT Id FROM Account WHERE createdDate > :d];
delete accounts;

You can add all other objects as well, simply by changing the type from account to contact, lead, etc.

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.