2

Several developers add a lot of features to our production org, so we refresh our sandboxes pretty frequently, wiping our test data. Recreating test data for 10+ objects every other day is becoming repetitively frustrating.

This question was asked in the past and there are a couple duplicates as well. BUT. We are very secure about our data and don't trust any app/tool that is deemed 3rd party (whether or not it is a desktop version or a web version), so the accepted answer is not going to work for us.

Data Loader and Excel connector work one-object-at-a-time, so it is not efficient when dealing with just a few records that belong to a lot of different objects.

So I was wondering if there are other (Apex) ways to read data from Production and insert in a Sandbox (perhaps Web Services?). Fortunately, Salesforce allows us to run ONE class after each refresh, so I was thinking of writing a method that brings 'test data' over.

We will move only a small part of the production data. Maintaining the relationships is not super important, because we are OK with linking them manually as needed at the time of our testing... that is, minimize the effort as much as possible if we can't totally automate it.

Any pointers in the right direction will be awesome. Thank you!

  • 2
    I think you gave the answer yourself, no? Run Script After Sandbox Creation and Refresh – Robin De Bondt Apr 11 '16 at 15:19
  • Right, now in that class how do I insert data from production into the sandbox in question? That is, List<sObject> my_production_data = Database.query(my_SOQL_to_get_data_from_Production); then insert my_production_data into Sandbox in context. – Lightning Evangelist Apr 11 '16 at 16:00
  • Why do you need production data to test? A full sandbox or partial data sandbox is designed exactly to do that. – Robin De Bondt Apr 11 '16 at 21:19
  • We have one full sandbox, but the access to it is restricted to certain developers. It makes most sense (and perhaps easier) to copy over some production data for testing purposes instead of making up dummy data. All I am looking for is for a way to open up a database connection to the production instance from sandbox (or vice versa). – Lightning Evangelist Apr 11 '16 at 21:31
  • @Kal why do you even want up-to-date real life data for testing purposes? In that Apex class you can simply create a few records that you need and insert them. You can even link them with each other if needed – Novarg Apr 12 '16 at 14:01
2

Although I can't give you specific guidance because I don't know what queries you want to run to extract data or anything like that, I do have a way you can do this without having to run through x number of data loader times.

  1. Setup Data Loader CLI - it should be included with your GUI Data Loader, but I believe it's still Windows only.
  2. Configure your process-conf.xml file's beans with all queries and insert/updates you want to run.

Pro-tip: Make sure each bean perform what you are trying to do prior to automating the whole thing.

  1. Optional: Use ANT (the same tool the Force.com Migration Tool is built for/on) to script the execution of all of your beans into one command line execution. This will simplify the final script you need to schedule, let you change your 'program' as opposed to messing with the script file, and if you ever want to allow someone to execute this manually, this gives them a single command to run.

  2. Create a file to execute all of your beans (or ANT script) and use a scheduling tool to execute at whatever frequency you wish - I believe the native Task Scheduler for windows can perform this function. I'm not as familiar with portion as our Director of IS set this part up, but I can get more info if needed.


There isn't a whole lot out there on the Data Loader CLI but there is enough. If you need more guidance on how to use the CLI comment and I'll update my answer - hopefully with some references. This allows you to accomplish what you need without 3rd party tools (based on your post I'm assuming Data Loader is not considered 3rd Party), albeit with a little elbow grease on your end.

This is also an ideal solution for importing data to Salesforce from other systems that only have the ability to schedule the creation CSV's as opposed to having any APIs.

  • I like the concept. Will try it out and let you know how it goes. Really appreciate the help. Thank you! – Lightning Evangelist Apr 12 '16 at 14:14

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.