Skip to content

Instantly share code, notes, and snippets.

@az-ak
Last active November 17, 2021 11:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save az-ak/58f6043e886a069f0c65682f46349fe6 to your computer and use it in GitHub Desktop.
Save az-ak/58f6043e886a069f0c65682f46349fe6 to your computer and use it in GitHub Desktop.
Apex SandboxPostCopy example
global without sharing class SandboxPostCopyUpd implements SandboxPostCopy {
global void runApexClass(SandboxContext context) {
LIst<Contact> ConList = [SELECT ID FROM CONTACT];
for (Contact con : ConList) {
con.Email = 'dummy@example.com';
}
update ConList;
}
}
@isTest
public class SandboxPostCopyUpd_test {
static testMethod void testSandboxPostCopyScript() {
Account acct = new Account (Name='Acme');
insert acct;
Contact con = new Contact (FirstName='Yamada',LastName='Taro',AccountId=acct.Id,Email='Yamada@example.com');
insert con;
Test.testSandboxPostCopyScript(new SandboxPostCopyUpd(), '00D000000001111', '00D000000002222', 'sandboxName');
System.assertEquals(0,[SELECT count() FROM CONTACT WHERE Email !='dummy@example.com']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment