Sunday, November 10, 2019

Sandbox Refresh

Usually there are a lot of things needs to be done when doing sandbox refresh, e.g. activating uses, changing email address of contacts or other objects, etc.. We can plugin the sandbox refresh script mentioned here. However, we still have to write a lot of code or use tools to achieve many things needed depending on fullcopy or dev refresh.

We wrote framework to simplify the refresh of the sandbox, where we can add multiple plugins, and also added static resource configuration file which can help with plug in configuration.

1
2
3
public interface SandboxRefreshPlugin {
    String execute(SandboxRefreshTemplate sandboxRefreshTemplate);
}

We also wrote multiple plugins to do the actual work, e.g.
  • SandboxRefreshProvisionPlugin
    • This will provision the users.
    • e.g. activate them, change their profiles
    • in static resource, it is under ProvisionUserRecords tag
  • SandboxRefreshDataCreationPlugin
    • This will create sample data after refresh (useful for dev sandbox)
    • In static resource it is under sObjectRecords records
  • SandboxRefreshInvalidateEmailPlugin
    • This will invalidate email addressed for specified fields
    • E.g. Contact or other email address that might be used for sending emails
    • In static resource, it is under inValidateEmailsObjects
  • SandboxRefreshEncryptFieldsDataPlugin
    • This will encrypt the data for specified field
    • E.g. some of the PII, PHI data needs to be encrypted
    • In static resource it is under encryptFieldsData
Configuration static resource would help the plugin to be more configurable. Hence, we created static resource file as below

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{
  "ProvisionUserRecords": [
    {
      "userName": "test@test.com.cshah",
      "profile": "System Administrator",
      "isActive": true
    }
  ],
  "notificationEmails": "test@springsoa.com",
  "inValidateEmailsObjects": [
    {
      "sObjectName": "Contact",
      "emailFields": "Email"
    },
    {
      "sObjectName": "Lead",
      "emailFields": "Email"
    },
    {
      "sObjectName": "Case",
      "emailFields": "SuppliedEmail"
    }
  ],
  "encryptFieldsData": [
    {
      "sObjectName": "Contact",
      "sObjectFields": [
        {
          "fieldName": "AssistantPhone",
          "format": "999{N}{N}{N}{N}{N}{N}{N}"
        },
        {
          "fieldName": "Email",
          "format": "test@{S}{S}{S}{S}.com"
        }
      ]
    }
  ],
  "sObjectRecords": [
    {
      "sObjectName": "Account",
      "reference": "ISO_Account_1",
      "attributes": {
        "Name": "1 West Finance",
        "Type": "ISO"
      }
    },
    {
      "sObjectName": "Account",
      "reference": "Merchant_Account1",
      "attributes": {
        "Name": "The Carrington Group Limited",
        "Type": "Merchant"
      }
    },
    {
      "sObjectName": "Opportunity",
      "reference": "Opportunity1",
      "attributes": {
        "Name": "The Carrington Group Limited - 190529",
        "AccountId": "reference-Merchant_Account1",
        "StageName": "Approved",
        "CloseDate": "10/24/2018"
      }
    },
    {
      "sObjectName": "Account",
      "reference": "Merchant_Account2",
      "attributes": {
        "Name": "Otto Case",
        "Type": "Merchant"
      }
    },
    {
      "sObjectName": "Opportunity",
      "reference": "Opportunity2",
      "attributes": {
        "Name": "Otto Case - 190307",
        "AccountId": "reference-Merchant_Account2",
        "StageName": "Approved",
        "CloseDate": "10/24/2018"
      }
    }
  ]
}

Most of the script initiates the batch file, as the full copy data could be quite huge. Now all we need to do is to specify the class SandboxRefresh during the refresh of the sandbox.

Code can be installed using unmanaged package : https://login.salesforce.com/packaging/installPackage.apexp?p0=04t2E000003ZQyl  or can be downloaded from github https://github.com/springsoa/springsoa-salesforce



1 comment:

JacobHarman said...
This comment has been removed by the author.