You need to sign in to do that
Don't have an account?
Lovel Panchal
I am not able to clear the test even when all is working fine (Apex Specialist > 2.Synchronize Salesforce data with an external system)
I am facing issues to clear the mentioned test, Please can some one look into this and help me out.
Help appericiated.
The Code which I am using:
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;
}
}
}
Help appericiated.
The Code which I am using:
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;
}
}
}
How many records do you have in the Product2 table. There are 22 records that should by imported from the remote endpoint. Therefore, you should have >= 22 records.
Jeff Douglas
Trailhead Developer Advocate
The challenge states that you need to update the equipments. In your code you are adding the equipments from the webservice results, since there is no Salesforce ID known.
You will need to add the external id field to your upsert statement to make sure that the equipments are updated and not added. Like this:
Happy coding!
Best regards,
Martijn Schwärzer