Clear Magento ID filed on archived products in Salesforce

Salesforce allows you to archive products. See How do I Archive a Product or Price Book? for more information. This action may cause an issue. Imagine you archive products which were synchronized from Magento to Salesforce and Magento is trying to update an archived product. Salesforce will not let you perform that action causing an error. 

Instructions

First of all, we strongly advise you NOT use archive feature in Salesforce until Salesforce enhances their experience around archiving products. However, if you found yourself in this situation, there is a way to manually fix the conflict between both systems.

  1. Login to your Salesforce Organization
  2. Navigate to the Developer Console
  3. Find your way to the Debug tab
  4. Click on Open Execute Anonymous Window
  5. In the popup, copy paste this script

    List<Product2> l_products = [SELECT ID,tnw_mage_basic__Magento_ID__c FROM Product2 WHERE IsArchived = true AND tnw_mage_basic__Magento_ID__c != null];
    for(Product2 product : l_products) {
        product.tnw_mage_basic__Magento_ID__c = null;
    }
    update l_products;
  6. Click Execute button