0

I am working on Apex Specialist super badge. While doing second challenge it is giving below error : 

There was an unhandled exception. Please reference ID: CTZYSSRH. Error: Faraday::ClientError. Message: INVALID_FIELD: where name = 'UPS 3000 VA' and Maintenance_Cycle__c = 180 and Lifespan_Months__c ^ ERROR at Row:1:Column:56 No such column 'Maintenance_Cycle__c' on entity 'Product2'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

Below is my code :

    public with sharing class WarehouseCalloutService {
    private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment';
    @Future(callout=true)
    public static void runWarehouseEquipmentSync(){
        List<Product2> lstOfEqup = new List<Product2>();
        
        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<Json2Apex> lstOfEquipments = (List<Json2Apex>) JSON.deserialize(response.getBody(), List<Json2Apex>.class);
            
            for(Json2Apex inst : lstOfEquipments){
                Product2 prod = new Product2();
                prod.Anonymous_App__Cost__c = inst.cost;
                prod.Anonymous_App__Lifespan_Months__c = inst.lifespan;
                prod.Anonymous_App__Maintenance_Cycle__c= inst.maintenanceperiod;
                prod.Name = inst.name;
                prod.Anonymous_App__Current_Inventory__c = inst.quantity;
                prod.Anonymous_App__Replacement_Part__c = inst.replacement;
                prod.Anonymous_App__Warehouse_SKU__c = inst.sku;
                lstOfEqup.add(prod);
                
                System.debug('cost'+inst.cost);
                System.debug('sku'+inst.sku);
                System.debug('maintenanceperiod'+inst.maintenanceperiod);
            }
        }
        
        if(lstOfEqup != null && lstOfEqup.size() > 0){
            System.debug('lstOfEqup'+lstOfEqup);
            UPSERT lstOfEqup Anonymous_App__Warehouse_SKU__c;
        }
    }
    
    //Wrapper class for Responce details.
    private class Json2Apex{
        private String id;
        private Integer cost;
        private Integer lifespan;
        private Integer maintenanceperiod;
        private String name;
        private Integer quantity; 
        private boolean replacement;
        private String sku;          
    }
}

In my org, Namespaces are enabled. I am stuck at this error. Not able to understand what to do. enter image description here

  • Seems like your org that you are validating against has a namespace configured. That will cause all sorts of problems with the validation. I'd suggest starting again against a fresh org and not using a namespace. – Daniel Ballinger Apr 6 '18 at 8:31
0

I think your issue is the Anonymous_app__ prefix on your field names on Product2. I went back and checked the org I completed this badge in and none of the custom fields contained this prefix. I suspect that when you are trying to complete the challenge trailhead is making assert calls using just Maintenance_cycle__c instead of Anonymous_app__Maintenance_cycle__c and that is the error that is being thrown as a result.

  • I have tried it using Maintenance_cycle__c, but still the error is same. @consulps – Nitin Gupta Apr 6 '18 at 7:09
0

As per my comment, it appears you have a namespace configured in the org you are trying to validate against. This will cause problems with the validation code that Trailhead runs. It won't be able to resolve the field names due to the Anonymous_App__ prefix.

You will need to create a new org to perform the validation against.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.