Skip to content

Instantly share code, notes, and snippets.

@mhamzas
Forked from az-ak/SandboxPostCopyUpd.cls
Created November 17, 2021 11:15
Show Gist options
  • Save mhamzas/534b7da9a3ca6a7fea32c7cd5f50065a to your computer and use it in GitHub Desktop.
Save mhamzas/534b7da9a3ca6a7fea32c7cd5f50065a 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