SandboxPostCopy interface not working on custom object/custom setting field in PostCopy Apex class
Apex , Custom Objects , Sandbox
Last updated 2017-05-09 ·Reference W-3027449 ·Reported By 8 users
Summary
If we use context.sandboxId() or context.sandboxName() and assign the value to a String variable or a Text custom object/custom setting field in PostCopy Apex class, common.apex.runtime.impl.ExecutionException: Illegal arguments is encountered and the assignment does not work.
Repro
1. In your production org created custom settings like below
Label: Environment Settings
Fields
Label:Environment Id Type:Text(18)
Label:Environment Name Type:Text(150)
Label:Environment Type Type:Text(150)
Label:Environment URL Type:Text(150)
2. Click on Manage and set values like below
Environment Id: <Your Org Id>
Environment URL: <Your instance URL like na2.salesforce.com>
Environment Type: Production
Environment Name: <This can be anything>
3. Create a Apex class to use SandboxPostCopy interface like below to update the values in Sandbox
global class sandboxCreateRefreshScript implements SandboxPostCopy
{
global void runApexClass(SandboxContext context)
{
Environment_Settings__c es = Environment_Settings__c.getorgdefaults();
es.Environment_Type__c = 'Sandbox';
es.Environment_URL__c = URL.getSalesforceBaseUrl().toexternalform();
es.Environment_Id__c = context.sandboxId();
es.Environment_Name__c = context.sandboxName();
System.debug('Hello Tester Pester ' + context.organizationId() + ' ' + context.sandboxId() + context.sandboxName());
update es;
}
}
4. Create a sandbox or refresh existing one using the Apex class above to be executed
5. After completion, you will see that no debug logs are created and custom settings values have not changed from Production
Workaround
NA
Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.