You need to sign in to do that
Don't have an account?
Mathieu Perrin 13
Method does not exist or incorrect signature: Test.testSandboxPostCopyScript(SandboxPostRefresh, Id, Id, String)
Hello,
I created an Apex class to be launched after a sandbox refresh.
I am trying to implement the test class corresponding but I got the following error :
Here is my test class :
And my post refresh class :
I created an Apex class to be launched after a sandbox refresh.
I am trying to implement the test class corresponding but I got the following error :
Method does not exist or incorrect signature: Test.testSandboxPostCopyScript(SandboxPostRefresh, Id, Id, String)Someone already had this error ? My class is set on version 38.
Here is my test class :
@isTest private class SandboxPostRefreshTest { @isTest static void testSandboxPostRefresh() { Test.startTest(); SandboxPostRefresh ClassInstance = new SandboxPostRefresh(); System.Test.testSandboxPostCopyScript(ClassInstance, UserInfo.getOrganizationId(), UserInfo.getOrganizationId(), 'sandboxName'); Test.stoptest(); } }
And my post refresh class :
global class SandboxPostRefresh { global void runApexClass(SandboxContext context) { NexthinkProvider np = NexthinkProvider.getInstance(); String[] opportunityRecordTypes = new String[]{'New Customer','NBS','Services','Renewal','Upsell'}; Schema.DescribeSObjectResult oSchema = Schema.SObjectType.Opportunity; Map<String,Schema.RecordTypeInfo> rtMapByName = oSchema.getRecordTypeInfosByName(); // Create accounts List<Map<String, Object>> accountsProperties = new List<Map<String, Object>>(); for (Integer i = 1; i <= 13; i++) { String industry = Randomizer.getRandomPickListValue(Account.sObjectType, null, 'Industry', false); Account a = new Account(); Randomizer.getRandomPickListValue(null, a, 'Industry', false); Map<String, Object> accountProperties = new Map<String, Object>(); if(i == 13) { accountProperties.put('Name', 'Direct'); } else { accountProperties.put('Name', Randomizer.getRandomCompanyName()); } accountProperties.put('Industry', Randomizer.getRandomPickListValue(Account.sObjectType, null, 'Industry', false)); if(i <= 3) { accountProperties.put('Type', 'Potential Customer'); } else if(i > 3 && i <= 6) { accountProperties.put('Type', 'Customer'); } else if(i > 6 && i <= 9) { accountProperties.put('Type', 'Potential Partner'); accountProperties.put('Industry', 'Technology'); } else if(i > 9 && i <= 13) { accountProperties.put('Type', 'Partner'); accountProperties.put('Industry', 'Technology'); } accountProperties.put('CurrencyIsoCode', Randomizer.getRandomCurrency()); accountProperties.put('Country__c', Randomizer.getRandomCountry()); accountsProperties.add(accountProperties); } List<Account> accounts = np.createAccounts(accountsProperties); List<Account> partners = new List<Account>(); for(Account a : accounts) { if(a.Type == 'Potential Partner' || a.Type == 'Partner') { partners.add(a); } } List<Map<String, Object>> contactsProperties = new List<Map<String, Object>>(); List<Map<String, Object>> opportunitesProperties = new List<Map<String, Object>>(); for(Account a : accounts) { // Create contacts Map<String, Object> contactProperties = new Map<String, Object>(); contactProperties.put('FirstName', Randomizer.getRandomFirstname()); contactProperties.put('LastName', Randomizer.getRandomLastname()); contactProperties.put('Phone', Randomizer.getRandomPhoneNumber()); contactProperties.put('AccountId', a.Id); String firstname = (String) contactProperties.get('FirstName'); String lastname = (String) contactProperties.get('LastName'); contactProperties.put('Email', firstname.toLowerCase() + '.' + lastname.toLowerCase() + '@' + a.Name.toLowerCase() + '.com'); contactProperties.put('Country__c', a.Country__c); contactProperties.put('LeadSource', Randomizer.getRandomPickListValue(Contact.sObjectType, null, 'LeadSource', false)); contactsProperties.add(contactProperties); if(a.Name != 'Direct' && a.Type != 'Partner' && a.Type != 'Potential Partner') { for (Integer i = 1; i <= 3; i++) { // Create opportunities Map<String, Object> opportunityProperties = new Map<String, Object>(); String partnerName; if(Randomizer.getRandomBoolean()) { Account partner = partners.get(Randomizer.getRandomNumber(6)); partnerName = partner.Name; opportunityProperties.put('Partner_Lookup__c', partner.Id); } else { partnerName = 'Direct'; } Schema.RecordTypeInfo rt = rtMapByName.get(Randomizer.getRandomString(opportunityRecordTypes)); opportunityProperties.put('RecordTypeId', rt.getRecordTypeId()); opportunityProperties.put('Name', a.Name + '_' + partnerName + '_' + rt.getName()); opportunityProperties.put('AccountId', a.Id); opportunityProperties.put('CurrencyIsoCode', a.CurrencyIsoCode); opportunityProperties.put('CloseDate', Date.today().addDays(Randomizer.getRandomNumber(90))); opportunityProperties.put('StageName', 'Unqualified'); opportunityProperties.put('Probability', 11); opportunityProperties.put('LeadSource', Randomizer.getRandomPickListValue(Opportunity.sObjectType, null, 'LeadSource', false)); opportunityProperties.put('Contract_Start_Date__c', ((Date) opportunityProperties.get('CloseDate')).addDays(1)); String contractCommitment = Randomizer.getRandomPickListValue(Opportunity.sObjectType, null, 'Contract_Commitment__c', false); opportunityProperties.put('Contract_Commitment__c', contractCommitment); if(contractCommitment == '<1 Year') { opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(90)); } else if(contractCommitment == '1 Year') { opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(Randomizer.getRandomNumber(365))); } else if(contractCommitment == '2 Years') { opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(365*2)); } else if(contractCommitment == '3 Years') { opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(365*3)); } else if(contractCommitment == '4 Years') { opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(365*4)); } else if(contractCommitment == '5 Years') { opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(365*5)); } else { opportunityProperties.put('Contract_End_Date__c', ((Date) opportunityProperties.get('Contract_Start_Date__c')).addDays(500)); } opportunitesProperties.add(opportunityProperties); } } } List<Contact> contacts = np.createContacts(contactsProperties); List<Opportunity> opportunities = np.createOpportunities(opportunitesProperties); // Get all products Map<String, Product2> productsMap = new Map<String, Product2>(); for(Product2 product : [SELECT Id, Name FROM Product2]) { productsMap.put(product.Name, product); } // Create OpportunityLineItem Map<Opportunity,List<Object>> olisMap = new Map<Opportunity,List<Object>>(); for(Opportunity o : opportunities) { List<Object> tempList = new List<Object>(); List<Product2> opportunityProductList = new List<Product2>(); Map<String, Object> oliProperties = new Map<String, Object>(); oliProperties.put('Description', 'SKU'); if(o.RecordTypeId == rtMapByName.get('New Customer').getRecordTypeId() || o.RecordTypeId == rtMapByName.get('Upsell').getRecordTypeId()) { oliProperties.put('Quantity', 100); opportunityProductList.add(productsMap.get('Endpoint Collector - License')); if(Randomizer.getRandomBoolean()) { opportunityProductList.add(productsMap.get('Endpoint Collector - Maintenance 1yr')); } else { opportunityProductList.add(productsMap.get('Endpoint Collector - Subscription 1yr')); } if(Randomizer.getRandomBoolean()) { opportunityProductList.add(productsMap.get('Time & Material billed upon completion - per day')); } } if(o.RecordTypeId == rtMapByName.get('NBS').getRecordTypeId()) { oliProperties.put('Quantity', 5); opportunityProductList.add(productsMap.get('Baseline Service 1-Engine')); } if(o.RecordTypeId == rtMapByName.get('Renewal').getRecordTypeId()) { oliProperties.put('Quantity', 1000); if(Randomizer.getRandomBoolean()) { opportunityProductList.add(productsMap.get('Renewal Endpoint Collector - Subscription 1yr')); } else { opportunityProductList.add(productsMap.get('Renewal Endpoint Collector - Maintenance 1yr')); } } if(o.RecordTypeId == rtMapByName.get('Services').getRecordTypeId()) { oliProperties.put('Quantity', 10); Integer random = Randomizer.getRandomNumber(3); if(random == 1) { opportunityProductList.add(productsMap.get('Time & Material billed upon completion - per day')); } else if(random == 2) { opportunityProductList.add(productsMap.get('Service Fee Billed in Advance')); } else if(random == 3) { opportunityProductList.add(productsMap.get('Fixed fee billed upon milestone completion')); } } tempList.add(opportunityProductList); tempList.add(oliProperties); olisMap.put(o, tempList); } np.addProducts(olisMap); } }
I think you may need to change your class a bit as well.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_System_SandboxPostCopy.htm
If you look at the above link, you can see that the class is implemented from SandboxPostCopy().
Try changing your class to this:
This should make your parameters correct for your testSandboxPostCopyScript() method.
All Answers
Try renaming your test method:
Hope this helps!
I tried to rename my test method but same error.
I think you may need to change your class a bit as well.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_System_SandboxPostCopy.htm
If you look at the above link, you can see that the class is implemented from SandboxPostCopy().
Try changing your class to this:
This should make your parameters correct for your testSandboxPostCopyScript() method.