• Rahul Jog
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello team,
 
I have stuck in Apex specialist superbadge(Challenge 5), Please help me with the resolution. I have written class WarehouseCalloutService, which is getting executed without error if i called it from debug log But getting runtime error while running test class written for that class.
 
Getting Error :- FATAL_ERROR System.TypeException: Invalid conversion from runtime type Map<String,ANY> to List<ANY>
 
 
class:-WarehouseCalloutService
global with sharing class WarehouseCalloutService {
    
private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment';    
    @future (callout=true)
    public static void runWarehouseEquipmentSync() {
        //ToDo: complete this method to make the callout (using @future) to the
        //      REST endpoint and update equipment on hand.
        Http http = new Http();
        HttpRequest req  = new HttpRequest();
        req.setEndpoint(WAREHOUSE_URL);
        req.setMethod('GET');
        HttpResponse res = http.send(req);
        
        if(res.getStatusCode()==200){
            List<object> results = (List<object>)JSON.deserializeUntyped(res.getBody());
            system.debug(results);
            List<Product2> productlist = new List<Product2>();
            for(Object o : results){
                Map<string,Object> eqp = (Map<String,Object>)o;
                system.debug(eqp);
                Product2 equipment = new Product2();                
                equipment.Replacement_Part__c = (Boolean)eqp.get('replacement');
                equipment.Current_Inventory__c = (Decimal)eqp.get('quantity');
                equipment.Lifespan_Months__c = (Integer)eqp.get('lifespan');
                equipment.Maintenance_Cycle__c = (Integer)eqp.get('maintenanceperiod');
                equipment.Name = (String)eqp.get('name');
                equipment.Cost__c = (Integer)eqp.get('cost');
                equipment.ProductCode = (String)eqp.get('_id');
                equipment.Warehouse_SKU__c = (String)eqp.get('sku');
                productlist.add(equipment);
            }
            system.debug(productlist);
            upsert productlist;
        }
    }
}