Moving Production Data to a Sandbox

Populating a Developer Sandbox can be a painstaking task, but using a data loader along with external ids can help simplify the process and save you a little time. The first thing you will need to decide is what data you will need to work with in your Sandbox. Since the amount of storage is far less in this type of Sandbox, you will most likely not be able to copy everything over. In the following example, we will use Jitterbit to move over Accounts and their Contacts that have open Opportunities. You may need to further filter your criteria if you have a lot of open Opportunities but this example should at least get you started.

The first thing we’ll do is create all of the queries, let’s start with the Account object.

  1. Open Jitterbit Data Loader
  2. Double click on New Query
  3. Select your Production Login and click Next
  4. Select the Account object and click Next
  5. Check all of the fields you would like to copy over
  6. Manually enter the WHERE clause to only include Accounts that have Ids IN the Opportunity Subquery and click Next

  7. Enter the Name of the file e.g. AccountExtract, leaving the remaining defaults and click Next
  8. Leave the defaults and click Next again
  9. Click Finish then click on Run Query

Most of the steps for selecting the Contacts will be the same with a few differences.

  1. Repeat steps 1 – 3
  2. In Step 4, Select the Contact object, click Next and Select the desired fields
  3. Manually enter the WHERE clause to only include Contacts that are related to Accounts that have Ids IN the Opportunity Subquery and click Next

  4. Repeat steps 7 – 9, with using an appropriate name for the file, e.g. ContactExtract

Once again the steps will be very similar for selecting the Opportunities:

  1. Repeat steps 1 – 3
  2. In Step 4, Select the Opportunity object, click Next and Select the desired fields
  3. Since we are working directly on the Opportunity object you will not need to use a semi-join and can have the WHERE clause just include Opportunities that are not closed

  4. Repeat steps 7 – 9, with using an appropriate name for the file, e.g. OpportunityExtract

Now that we have all of the data in hand, we’ll need to add some external ids to our objects in the Sandbox. Since Summer ’14 has increased the number of allowed external ids per object, it may further simplify things to have these fields already in the Production org but for some that can be confusing so I typically just add them after a Sandbox refresh.

  1. Login to your Developer Sandbox
  2. Go to Setup -> Customize -> Accounts -> Fields
  3. Click on New Field
  4. Select Text then Next
  5. Enter ProductionId for the field label
  6. Enter 18 for the length
  7. Check Unique and External Id, leave all remaining defaults and click Next
  8. Select the desired field-level security options and click Next
  9. Select the desired layouts to add the field to and click Save

Repeat the above steps for both the Contact and Opportunity objects. Once all of the external ids have been added we can begin the import process.

  1. Return to Jitterbit
  2. Double click on New Upsert
  3. IMPORTANT – make sure you select your Sandbox Login and click Next
  4. Select the Account object from Step 1 and the newly created ProductionId from Step 2 and click Next
  5. Browse for the AccountExtract file created above and click Next
  6. A popup with a subset of the data will open, click Continue
  7. Leave the defaults and click Next
  8. Leave the defaults again and click Map & Finish
  9. Click Auto Map to align all matching fields
  10. Double click the Id on the right hand side and delete the Id between the <trans> tags then click OK
  11. Repeat step 10 for all fields that are lookups to other objects (User lookups are ok)
  12. Drag the Id from the left hand side and drag it over to the ProductionId on the right hand side
  13. Click Finish then click Run Upsert

The steps will be repeated again for both the Contact and Opportunity object with the following three additional steps.

  1. Once you have reached step 10, you will want to make sure to clear the mapping for the AccountId
  2. Click the plus sign to expand the Account folder on the top right hand side to reveal the ProductionIdScreenshot 2015-09-20 20.48.31
  3. Drag the AccountId from the left up to the ProductionId field under the Account folder

Now, whenever we need to update the data from Production to Sandbox, we can simply extract the updated data, keep the fields and file names the same as our original extract and just re-run the saved Upserts.




Leave a comment

Your email address will not be published. Required fields are marked *