0

I'm trying to pass second challenge of Apex Specialist Superbadge and got error:

Challenge Not yet complete... here's what's wrong: The runWarehouseEquipmentSync method does not appear to have run successfully. Could not find a successfully completed @future job for this method. Make sure that you run this method at least one before attempting this challenge. Since this method is annotated with the @future method, you may want to wait for a few seconds to ensure that it has processed successfully.

The runWarehouseEquipmentSync method does not appear to have run successfully

What it can be? I used this class:

public with sharing class WarehouseCalloutService {

    private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment';

    @future(callout=true)
    // complete this method to make the callout (using @future) to the
    // REST endpoint and update equipment on hand.
    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 the request is successful, parse the JSON response.
        String ret = '';
        if (response.getStatusCode() == 200) {
            // Deserialize the JSON string into collections of primitive data types.
            List<Object> results = (List<Object>) JSON.deserializeUntyped(response.getBody());

            List<Product2> LstProduct = new List<Product2>();
            for(Object obj : results)
            { 
                Map<String, Object> mapobj = (Map<String, Object>)obj;
                Product2 product = new Product2();

                Integer maintenanceperiod = (Integer)mapobj.get('maintenanceperiod');               
                Integer Lifespan = (Integer)mapobj.get('lifespan');
                Integer Cost = (Integer)mapobj.get('cost');
                Boolean replacement = (Boolean)mapobj.get('replacement');
                Integer quantity = ((Integer)mapobj.get('qIntegerntity'));
                product.Name  = (String)mapobj.get('name'); 
                product.Maintenance_Cycle__c = Integer.valueof(maintenanceperiod);
                product.Cost__c = Cost;
                product.Current_Inventory__c = quantity;
                product.Lifespan_Months__c = Lifespan; 
                product.Replacement_Part__c = replacement;
                product.Warehouse_SKU__c = (String) mapobj.get('sku');
                product.ProductCode = (String)mapobj.get('_id');       
                LstProduct.add(product);
            }
            System.debug(LstProduct);
            upsert LstProduct;

        }
    }
}
4
  • WarehouseCalloutService.runWarehouseEquipmentSync(); in Anonimous ?
    – Dmitry
    Aug 3, 2016 at 16:28
  • I do not understand what it means
    – Dmitry
    Aug 3, 2016 at 16:29
  • Did you run the method in the anonymous apex window? Aug 3, 2016 at 16:44
  • Yes, I run the method in the anonymous apex window.
    – Dmitry
    Aug 3, 2016 at 18:29

3 Answers 3

6

Try running this query in your developer org:

SELECT Id, JobType, MethodName, Status FROM AsyncApexJob WHERE CompletedDate = TODAY

This query will return all completed batch, future, and queryable jobs that were completed today.

If you don't see your @future method in the list, then there's something wrong, but if you see a status of Completed, then something might be wrong with the code you wrote- you might need to update a field, or name something differently to conform to the challenges criteria.

As per the docs:

AsyncApexJob

Represents an individual Apex sharing recalculation job, a batch Apex job, a method with the future annotation, or a job that implements Queueable.

(Emphasis mine)

4
  • I got Completed. What I can check?
    – Dmitry
    Aug 3, 2016 at 16:49
  • 2
    Do not try to edit answers in an attempt to reply. Replies should be limited to comments only. Aug 3, 2016 at 16:51
  • I can see from the image you tried to edit into the answer that some of those were failures- gather more information about those failures, and try to debug them. Make sure any new runs execute without issues. If you can't figure out why they aren't executing successfully, gather some information, and ask another question. Aug 3, 2016 at 16:59
  • In that failures was just error in upsert syntax. I can't find what I write wrong.
    – Dmitry
    Aug 3, 2016 at 17:04
0

I faced the same issues too, trying all the ways as said above but the error in my scenario was that in the Remote Site Settings the endpoint was not added. The Endpoint here needs to be of the link "https://th-superbadge-apex.herokuapp.com/equipment". On adding it, the Challenge got cleared. Hope it helps

1
0

In case someone still have the error, confirm you read this part while checking the Challenge:

Before checking this section, run the WarehouseCalloutService.runWarehouseEquipmentSync() method at least once, confirming that it’s working as expected.```

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .