function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lisa SchutterLisa Schutter 

PostCopy Refresh Script not executing after Sandbox refresh/Creation

Hi Guys, I am trying to create records after refresh in my Dev sandbox. But after my Sandbox creation the record did not show up, does anyone see something that is not correct in my code below?  I read this know issue, but this seams to be solved already us (EU3 and CS88).

I put the name of the Class in the Apex Class field, from the Sandbox options:

User-added image
 
global class sandboxRefreshScript implements SandboxPostCopy{
global void runApexClass(SandboxContext context)
{
 
List<Account> accounts = new List<Account>();

Account a1 = new Account();
a1.Name = 'J&T Autolease';
a1.Ownerid = '005w0000005bvNR';
a1.Type = 'LeaseCo';
a1.Status__c = 'Partner';    
a1.BillingCity = 'Greensboro';
    

accounts.add(a1);

Account a2 = new Account();
a2.Name = 'Test Account ';
a2.Type = 'Client';
a2.BillingState = 'NC';
a2.BillingCity = 'Greensboro';    
 
accounts.add(a2);
 
insert Accounts;
    
List<Contact> contacts = new List<Contact>();

Contact b1 = new Contact();
b1.Salutation = 'Mr.';
b1.FirstName = 'Pieter';
b1.LastName = 'Pan';
b1.Email = 'c.leusink@newmotion.com';    
b1.Accountid = a1.ID;    

contacts.add(b1);

insert Contacts;
List<Opportunity> opportunities = new List<Opportunity>();

Opportunity c1 = new Opportunity();
c1.Name = 'Zonnestraal';
c1.Ownerid = '005w0000005bvM4';
c1.StageName = 'Intake';
c1.Accountid = a1.ID;    

opportunities.add(c1);

insert Opportunities;

List<Payment_Account__c> paymentaccounts = new List<Payment_Account__c>();

Payment_Account__c d1 = new Payment_Account__c();
d1.Name = 'Zonnestraal';
d1.Ownerid = '005w0000005bvM4';
d1.Billing_Name__c = 'Zonnestraal BV';   
d1.Billing_Email__c = 'l.schutter@newmotion.com';
d1.Payment_Terms__c = '14';
d1.Billing_Address__c = 'rue de Bastonge 4';      
d1.Billing_PostalCode__c = 'rue de Bastonge 4';      
d1.Billing_City__c = 'Gorbous';      
d1.Billing_Country__c = 'LU'; 

paymentaccounts.add(d1);

insert paymentaccounts;       
}
}

 
Best Answer chosen by Lisa Schutter
Lisa SchutterLisa Schutter
Just firgured this out myself, we didn't have the Billing State 'NC' as an option. Without that state, the script runned perfectly.

All Answers

Lisa SchutterLisa Schutter
https://success.salesforce.com/issues_view?id=a1p300000008epFAAQ this known issue
Lisa SchutterLisa Schutter
Just firgured this out myself, we didn't have the Billing State 'NC' as an option. Without that state, the script runned perfectly.
This was selected as the best answer