You need to sign in to do that
Don't have an account?

Apex Superbadge - The runWarehouseEquipmentSync method does not appear to have run successfully.
Greetings,
In point 2, i cant check it as sucess because it show the following 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.This is my code:
Warehouse Callout Service
public with sharing class WarehouseCalloutService { private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment'; // complete this method to make the callout (using @future) to the // REST endpoint and update equipment on hand. @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 the request is successful, parse the JSON response. if (response.getStatusCode() == 200) { // Deserialize the JSON string into collections of primitive data types. List<Object> equipments = (List<Object>) JSON.deserializeUntyped(response.getBody()); List<Product2> products = new List<Product2>(); for(Object o : equipments){ Map<String, Object> mapProduct = (Map<String, Object>)o; Product2 product = new Product2(); product.Name = (String)mapProduct.get('name'); product.Cost__c = (Integer)mapProduct.get('cost'); product.Current_Inventory__c = (Integer)mapProduct.get('quantity'); product.Maintenance_Cycle__c = (Integer)mapProduct.get('maintenanceperiod'); product.Replacement_Part__c = (Boolean)mapProduct.get('replacement'); product.Lifespan_Months__c = (Integer)mapProduct.get('lifespan'); product.Warehouse_SKU__c = (String)mapProduct.get('sku'); product.ProductCode = (String)mapProduct.get('_id'); products.add(product); } if(products.size() > 0){ System.debug(products); upsert products; } } } }
Warehouse Callout Service Mock
@isTest global class WarehouseCalloutServiceMock implements HttpCalloutMock { // implement http mock callout global HttpResponse respond(HttpRequest request){ System.assertEquals('https://th-superbadge-apex.herokuapp.com/equipment', request.getEndpoint()); System.assertEquals('GET', request.getMethod()); // Create a fake response HttpResponse response = new HttpResponse(); response.setHeader('Content-Type', 'application/json'); response.setBody('[{"_id":"55d66226726b611100aaf741","replacement":false,"quantity":5,"name":"Generator 1000 kW","maintenanceperiod":365,"lifespan":120,"cost":5000,"sku":"100003"}]'); response.setStatusCode(200); return response; } }Warehouse Callout Service Test
@isTest private class WarehouseCalloutServiceTest { // implement your mock callout test here @isTest static void WarehouseEquipmentSync(){ Test.startTest(); // Set mock callout class Test.setMock(HttpCalloutMock.class, new WarehouseCalloutServiceMock()); // This causes a fake response to be sent from the class that implements HttpCalloutMock. WarehouseCalloutService.runWarehouseEquipmentSync(); Test.stopTest(); System.assertEquals(1, [SELECT count() FROM Product2]); } }In another hand, I created an Remote Site Detail to bring access to JSON external list "Equipment". The debugs are made by "Execute Anonymous Window" option and Run "Warehouse Callout Service Test" class. Finally, I change to visible all Product's fields for all profiles.
Can anyone help me?
Thanks & Regards!
May I suggest you, please check with below link which might help you to accelerate further with above requirement.
- https://developer.salesforce.com/forums/?id=906F0000000kE7DIAU
- https://salesforce.stackexchange.com/questions/134346/could-not-find-a-successfully-completed-future-job
Hope this helps.Thanks,
Nagendra.
Hi Nagendra,
Thanks for your help, but I cant resolve my problem with these post. Im very frustrated because I debug my code and it works (Test debug works correctly and anonymous window upsert the JSON list) but Future Method isnt work (I launch the query of second hyperlink (SELECT Id, JobType, MethodName, Status FROM AsyncApexJob WHERE CompletedDate = TODAY) in Query Editor with 0 result.
Any idea about this future method is failing?
Thanks & Regard!
I am also facing the same error , I checkd there is no job running in Apex jobs.here is my code.
please help me out how to resolve this,
I added in remote site settings.
step2: code as below
public class WarehouseCalloutServiceMock {
private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment';
class Equipment{
public Id id{get;set;}
public boolean replacement{get;set;}
public Integer quantity{get;set;}
public String name{get;set;}
public Decimal maintenanceperiod{get;set;}
public Decimal lifespan{get;set;}
public Decimal cost{get;set;}
public String sku{get;set;}
}
// complete this method to make the callout (using @future) to the
// REST endpoint and update equipment on hand.
@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);
system.debug(response);
if(response.getStatusCode() == 200){
List<Object> results = (List<Object>) JSON.deserializeUntyped(response.getBody());
List<Product2> LstProduct = new List<Product2>();
for(Object o : results)
{
Map<String, Object> mapobj = (Map<String, Object>)o;
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;
}
}
}
step 3: ananoumous window
WarehouseCalloutService.runWarehouseEquipmentSync();
but not able to see any future jobs in log and if I execute the query as well.
select it and => add New Remote Site, => specify the Remote Site URL as "https://th-superbadge-apex.herokuapp.com/equipment"
=> then save.
rerun WarehouseCalloutService.runWarehouseEquipmentSync(); in ananoumous window
in query editor run the following query and make sure there is at least one completed job today related to runWarehouseEquipmentSync method
SELECT Id, JobType, MethodName, Status, createddate FROM AsyncApexJob WHERE CompletedDate = TODAY
Thats all
Step1: Setup --> Remote Site Settings --> New --> URL: https://th-superbadge-apex.herokuapp.com/equipment
Step2: The below Code
public with sharing class WarehouseCalloutService {
private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment';
// complete this method to make the callout (using @future) to the
// REST endpoint and update equipment on hand.
@future(callout=true)
public static void runWarehouseEquipmentSync(){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setMethod('GET');
request.setEndpoint(WAREHOUSE_URL);
HttpResponse response = http.send(request);
if(response.getStatusCode() == 200) {
List<Object> jsonResponse = (List<Object>)JSON.deserializeUntyped(response.getBody());
system.debug('~~ '+jsonResponse);
List<Product2> productList = new List<Product2>();
for(Object ob : jsonResponse) {
Map<String,Object> mapJson = (Map<String,Object>)ob;
Product2 pr = new Product2();
pr.Replacement_Part__c = (Boolean)mapJson.get('replacement');
pr.Name = (String)mapJson.get('name');
pr.Maintenance_Cycle__c = (Integer)mapJson.get('maintenanceperiod');
pr.Lifespan_Months__c = (Integer)mapJson.get('lifespan');
pr.Cost__c = (Decimal) mapJson.get('lifespan');
pr.Warehouse_SKU__c = (String)mapJson.get('sku');
pr.Current_Inventory__c = (Double) mapJson.get('quantity');
productList.add(pr);
}
if(productList.size()>0)
upsert productList;
}
}
}
Step3: Open Execute Anonymous window --> Run WarehouseCalloutService.runWarehouseEquipmentSync();
Step4: Query Editor --> Execute the query :SELECT Id, JobType, MethodName, Status, createddate FROM AsyncApexJob WHERE CompletedDate = TODAY
Now check the challenge!
Hope this helps!
It only accepting 'https://th-superbadge-apex.herokuapp.com/'. but not the /equipment. Can someone help.
https://trailblazers.salesforce.com/answers?id=9064S000000DRyLQAW
In Anonymous Window, use enqueueJob.
Let me know if it worked!
its showing like this
Challenge Not yet complete... here's what's wrong:
The WarehouseCalloutService class does not appear to have run successfully. Make sure that you run this class at least once before attempting this challenge. Since this class is implementing the queueable interface, you may want to wait to ensure that it has processed successfully.
private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment';
public static void runWarehouseEquipmentSync(){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setMethod('GET');
request.setEndpoint(WAREHOUSE_URL);
HttpResponse response = http.send(request);
if(response.getStatusCode() == 200) {
List<Object> jsonResponse = (List<Object>)JSON.deserializeUntyped(response.getBody());
system.debug('~~ '+jsonResponse);
List<Product2> productList = new List<Product2>();
for(Object ob : jsonResponse) {
Map<String,Object> mapJson = (Map<String,Object>)ob;
Product2 pr = new Product2();
pr.Replacement_Part__c = (Boolean)mapJson.get('replacement');
pr.Name = (String)mapJson.get('name');
pr.Maintenance_Cycle__c = (Integer)mapJson.get('maintenanceperiod');
pr.Lifespan_Months__c = (Integer)mapJson.get('lifespan');
pr.Cost__c = (Decimal) mapJson.get('lifespan');
pr.Warehouse_SKU__c = (String)mapJson.get('sku');
pr.Current_Inventory__c = (Double) mapJson.get('quantity');
productList.add(pr);
}
if(productList.size()>0)
upsert productList;
}
}
public static void execute(QueueableContext context){
runWarehouseEquipmentSync();
}
}
In Execute Anonymous Window, use enqueueJob.
System.enqueueJob(New WarehouseCalloutService());
https://trailblazers.salesforce.com/answers?id=9064S000000DRyLQAW