---
title: Sandbox Refresh Steps
slug: netsuite/sandbox-refresh-steps
docTags: 
createdAt: 2024-11-07T18:06:27.431Z
---

Refreshing a sandbox may require additional steps for Breadwinner for NetSuite. If you do not want to connect or use Salesforce sandbox to your production NetSuite account, you will need to delete the existing Breadwinner for NetSuite data from your sandbox. Follow the steps below to complete this process.

1. Visit the Breadwinner Tab - this will remove the production credentials and Netsuite Object configuration.
2. Assign the Admin Breadwinner Permission Set to the user that is going to sync the data (Needs to be a user with the Salesforce Admin profile)
3. Optional - Delete production data—During a refresh, Salesforce pulls in production data, including those in our custom objects (Customers, vendors, Sales Orders, Invoices, etc.). This is optional, but it should be done to limit confusion and for security reasons.
   1. Breadwinner setup tab -> Troubleshoot -> General
   2. Open up the "Delete NetSuite Data in Salesforce" Section
   3. Select the 'OTHERS' Tab (This may be your only option)
   4. Delete all the records—Salesforce limits us to deleting 10K records per click.
   5. See the "Delete Production NetSuite data from the sandbox" section below if you have a large amount of data.
4. Connect to the NetSuite Sandbox
5. Configure NS Object Sync to match production (these records were deleted in Sandbox Step 1).
6. Optional: Use the Additional Where filter script below to add "additional where filters" to the NetSuite Object Record.
   1. For companies with large amounts of data, this will help with the sync time to only pull in 'some' of the data.
7. Click the "Start Syncing NetSuite Objects" button on the Breadwinner Setup page.

## Additional Where filter script:

This will help if you have a large amount of data but don't need all the NetSuite data in your  Salesforce sandbox. This will add a date filter so we only bring in the last X days worth of data.

```apex
// Add your NetSuite Org Id
String netSuiteOrgId = 'XXXXXXXXX';

/* Add your Where Filter
* To filter by date, you need to convert the current date/time into an Epoch date
* which you can do here: https://www.epochconverter.com/
*/
String additionalWhereFilter = 'dateCreated>1672531200';

/*
* To update all the objects with the same filter, leave the objectLabelList empty
* Otherwise, add the list of objects to the objectLabelList. 
*
* Supported object labels are:
* Item, Customer, Contact, Vendor, Estimate, SalesOrder, CashSale, Invoice,
* ReturnAuthorization, CashRefund, CreditMemo, CustomerPayment, ItemFulfillment
* PurchaseOrder, VendorBill, VendorPayment, VendorCredit, Check
*/

List<String> objectLabelList = new List<String>{};
//List<String> objectLabelList = new List<String>{'Customer','Contact','SalesOrder','Invoice','CreditMemo'};

String qry = 'SELECT Id, Name, breadwinner_ns__Additional_Where_Filter__c ' +
'FROM breadwinner_ns__BW_NetSuite_Object__c ' +
'WHERE ' +
'Name LIKE \'' + netSuiteOrgId + ' - %\' AND ' +
'breadwinner_ns__NetSuite_Org_Id__c = \'' + netSuiteOrgId + '\' AND ' +
'breadwinner_ns__Subsidiary__r.breadwinner_ns__InternalId__c = NULL AND ' +
'breadwinner_ns__Subsidiary__r.Name = \'' + netSuiteOrgId + '\'';

if (!objectLabelList.isEmpty()){
  qry += ' AND breadwinner_ns__NetSuite_Object_Label__c IN (\'' + String.join(objectLabelList,'\',\'') + '\')';
}
System.debug(qry);

List<breadwinner_ns__BW_NetSuite_Object__c> nsObjectList = Database.query(qry);

List<breadwinner_ns__BW_NetSuite_Object__c> updateNSRecordList = new List<breadwinner_ns__BW_NetSuite_Object__c>();
for(breadwinner_ns__BW_NetSuite_Object__c nsRecord: nsObjectList){
  breadwinner_ns__BW_NetSuite_Object__c bwno = new breadwinner_ns__BW_NetSuite_Object__c(
    Id=nsRecord.Id,
    breadwinner_ns__Additional_Where_Filter__c = additionalWhereFilter
  );
  updateNSRecordList.add(bwno);
}

System.debug('updating records count: '+nsObjectList.size());
System.debug('updating records'+nsObjectList);

// Uncomment the line below after verifying the debug logs have the correct org id, object label, and filter.
// update updateNSRecordList;
```

## Delete Production NetSuite data from the sandbox.

Due to Salesforce limits, you can only delete 10,000 records at a time. Depending on the amount of data, you may also run into DML, CPU, or heap size errors, but rerunning the script over and over will eventually delete all the records.&#x20;

:::hint{type="info"}
You cannot delete production subsidiaries using Apex code. To delete production subsidiaries, go to the Breadwinner for NetSuite tab, then click the "Delete NetSuite Subsidiaries" button on the Troubleshoot > General > Delete NetSuite Data in Salesforce > Others tab.
:::

```apex
// Add your NetSuite Production Org Id
String productionNetSuiteOrgId = 'XXXXXXXXX';

/*
* This is the list of objects that the data will be deleted from.
*/
List<String> objList = new List<String>{
  'breadwinner_ns__BW_Location__c',
  'breadwinner_ns__BW_Metadata__c',
  'breadwinner_ns__BW_Currency__c',
  'breadwinner_ns__BW_Price_Level__c',
  'breadwinner_ns__BW_Employee__c',
  'breadwinner_ns__BW_Item__c',
  'breadwinner_ns__BW_Company__c',
  'breadwinner_ns__BW_Contact__c',
  'breadwinner_ns__BW_Estimate__c',
  'breadwinner_ns__BW_Sales_Order__c',
  'breadwinner_ns__BW_Invoice__c',
  'breadwinner_ns__BW_Return_Authorization__c',
  'breadwinner_ns__BW_Credit_Memo__c',
  'breadwinner_ns__BW_Payment__c',
  'breadwinner_ns__BW_Item_Fulfillment__c',
  'breadwinner_ns__BW_Bill__c',
  'breadwinner_ns__BW_Purchase_Order__c',
  'breadwinner_ns__BW_Check__c',
  'breadwinner_ns__BW_Address__c',
  'breadwinner_ns__BW_Line_Item__c',
  'breadwinner_ns__BW_Payment_Transaction__c',
  'breadwinner_ns__BW_Package__c',
  'breadwinner_ns__BW_Item_Price__c',
  'breadwinner_ns__BW_Inventory_Location__c'
};

for (String obj : objList){
  List<Object> recordList = Database.Query('SELECT Id, Name FROM ' + obj + ' WHERE breadwinner_ns__NetSuite_Org_Id__c =: productionNetSuiteOrgId LIMIT 10000');
  System.debug(recordList);
  // Uncomment the line below after verifying the debug logs.
  // Database.Delete(recordList,false);
}

```

:::hint{type="info"}
You could also put the above code into a batch apex class that calls itself until all the records are deleted and have it run after the sandbox refresh.
:::



