• Dominik Ryczek 5
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi,
I have a problem with step 2 in Apex Specialist Superbadge. I don't know how I should use field Warehouse_SKU__C as an external ID. This is my method from WarehouseCalloutService class:
@future(callout=true)
    public static void runWarehouseEquipmentSync(){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint(WAREHOUSE_URL);
        request.setMethod('GET');
        HttpResponse response = http.send(request);

        if(response.getStatusCode() == 200) {
            List<Product2> equipmentToSF = new List<Product2>();

            List<WarehouseResponse> equipment = WarehouseResponse.parse(response.getBody());

            for(WarehouseResponse itemFromWH : equipment) {
                Product2 item = new Product2();
                item.Warehouse_SKU__c = itemFromWH.sku;
                item.Name = itemFromWH.name;
                item.Maintenance_Cycle__c = itemFromWH.maintenancePeriod;
                item.Lifespan_Months__c = itemFromWH.lifespan;
                item.Cost__c = itemFromWH.cost;
                item.Current_Inventory__c = itemFromWH.quantity;
                item.Replacement_Part__c = true;

                equipmentToSF.add(item);
            }
            upsert equipmentToSF;

        }
    }
The problem is that every time I call this method, the equipment from external DB is duplicated instead of updated. I try to set Warehouse_SKU__c field as unique but it causes error.
I couldn't find how to use external ID field instead of using standard ID during upserting.

Thank you in advance :)
 
Hi,
I have a problem with step 2 in Apex Specialist Superbadge. I don't know how I should use field Warehouse_SKU__C as an external ID. This is my method from WarehouseCalloutService class:
@future(callout=true)
    public static void runWarehouseEquipmentSync(){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint(WAREHOUSE_URL);
        request.setMethod('GET');
        HttpResponse response = http.send(request);

        if(response.getStatusCode() == 200) {
            List<Product2> equipmentToSF = new List<Product2>();

            List<WarehouseResponse> equipment = WarehouseResponse.parse(response.getBody());

            for(WarehouseResponse itemFromWH : equipment) {
                Product2 item = new Product2();
                item.Warehouse_SKU__c = itemFromWH.sku;
                item.Name = itemFromWH.name;
                item.Maintenance_Cycle__c = itemFromWH.maintenancePeriod;
                item.Lifespan_Months__c = itemFromWH.lifespan;
                item.Cost__c = itemFromWH.cost;
                item.Current_Inventory__c = itemFromWH.quantity;
                item.Replacement_Part__c = true;

                equipmentToSF.add(item);
            }
            upsert equipmentToSF;

        }
    }
The problem is that every time I call this method, the equipment from external DB is duplicated instead of updated. I try to set Warehouse_SKU__c field as unique but it causes error.
I couldn't find how to use external ID field instead of using standard ID during upserting.

Thank you in advance :)