# Re-initialize a B2B Commerce Data

A few years ago, CC Admin had a button to "delete all" B2B commerce data, so you can easily reset your org's storefronts. This was very useful for development. Unfortunately, this button is gone. Here is how we can reproduce the same functionality with the help of the developer console.

# Step by Step

  1. Login into your org
  2. Open the Developer Console
  3. On the developer console, from the menu select "Debug > Open Execute Anonymous Window". A popup witht the title "Enter Apex Code" will open.
  4. Enter the following script. This WILL DELETE some CC Objects, so make sure you understand what you are doing, or ask an adult for help:
     delete [select Id from ccrz__e_order__c limit 1000];
     delete [select Id from ccrz__e_cart__c limit 1000];
     delete [select Id from ccrz__e_MenuItem__c limit 1000];
     delete [select Id from ccrz__e_Menu__c limit 1000];
     delete [select Id from ccrz__e_Term__c limit 1000];
     delete [select Id from ccrz__e_ShippingRate__c limit 1000];
     delete [select Id from ccrz__e_ProductMedia__c limit 1000];
     delete [select Id from ccrz__e_Promo__c limit 1000];
     delete [select Id from ccrz__e_Coupon__c limit 1000];
     delete [select Id from ccrz__e_RelatedProduct__c limit 1000];
     delete [select Id from ccrz__e_ProductGuide__c limit 1000];
     delete [select Id from ccrz__e_RelatedProductGroup__c limit 1000];
     delete [select Id from ccrz__e_FeaturedProduct__c limit 1000];
     delete [select Id from ccrz__e_CompositeProduct__c limit 1000];
     delete [select Id from ccrz__e_Spec__c limit 1000];
     delete [select Id from ccrz__e_PriceListItem__c limit 1000];
     delete [select Id from ccrz__e_ProductCategory__c limit 1000];
     delete [select Id from ccrz__e_Product__c limit 1000];
     delete [select Id from ccrz__e_Category__c limit 1000];
     delete [select Id from ccrz__e_PageSection__c limit 1000];
     delete [select Id from ccrz__e_StorefrontConfigSettings__c limit 1000];
     delete [select Id from ccrz__e_Rule__c limit 1000];
     delete [select Id from ccrz__e_PriceModifier__c limit 1000];
     delete [select Id from ccrz__e_AccountGroupPriceList__c limit 1000];
     delete [select Id from ccrz__e_PriceList__c limit 1000];
     delete [select Id from ccrz__e_AccountGroup__c limit 1000];
     delete [select Id from ccrz__e_PublicCacheContent__c limit 10000];
     delete [select Id from ccrz__e_PublicCache__c limit 10000];
     delete [select Id from ccrz__e_ProductIndex__c limit 10000];
     delete [select Id from ccrz__e_PrivateCacheContent__c limit 10000];
     delete [select Id from ccrz__e_PrivateCache__c limit 10000];
     delete [select Id from ccrz__e_Foo__c limit 10000];
     delete [select Id from ccrz__e_SiteIndex__c limit 10000];
     delete [select Id from ccrz__e_ContactAddr__c limit 10000];
     delete [select Id from ccrz__e_InvoiceItem__c limit 10000];
     delete [select Id from ccrz__e_AccountAddressBook__c limit 10000];
     delete [select Id from ccrz__e_StoredPayment__c limit 10000];
     delete [select Id from ccrz__e_TransactionPayment__c limit 10000];
     delete [select Id from ccrz__e_Invoice__c limit 10000];
     delete [select Id from ccrz__e_Attribute__c limit 10000];
     delete [select Id from ccrz__e_RichContent__c limit 10000];
     delete [select Id from ccrz__e_Subscriber_Page__c limit 10000];
     ccrz.cc_util_Reflection.deleteCustomSettings();
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43

    WARNING

    Note that we are limiting the deletion of the records to 1000 at a time. If you have more in your org, re-run the script until they are empty.

  5. Manually delete any Accounts created for B2B Commerce (E.g. PortalAccount, CCAnonymous, etc.). Make sure you are not deleting other accounts by mistake 😉
  6. Empty the recyle bin.
  7. That's it. CC Admin should should show up emtpy again, and you are ready to reconfigure your B2B Commerce storefront.

Keep in mind that we've only removed the metadata. Any custom code, static resource, file, etc. that you added should still remain.

# Appendix

# Checking the number of records

  1. From Setup, quick find "Storage" (or Data > Storage Usage from the menu)
  2. Make sure that B2B objects has a record count of "0". If they are not (e.g. CC Product Indices, CC Page Labels, etc.) re-run the script above to delete the records

# Emptying the recycling bin

  1. On the App launcher of your org (the one with the 9 dots), enter "Recycle" and select the "Recycle Bin" link.
  2. On the recyle bin view, click on "Empty Org Recycle Bin"

    Important

    Once you empty the recycle bin, you won't be able to recover the deleted records. Be very careful before proceeding

# One more thing

You could save the script as a file, and then use SFDX to execute it from your command line.

$ sfdx force:apex:execute --apexcodefile <FULL PATH TO SCRIPT FILE> --loglevel DEBUG


E.g.
$ sfdx force:apex:execute --apexcodefile /demo/ckz54Test/scripts/apex/cleanOrg.apex --loglevel DEBUG
1
2
3
4
5