You need to sign in to do that
Don't have an account?
Prasanth R
apex superbadge challenge2 npt cpmplete
i'm doing the apex specialist superbadge
https://trailhead.salesforce.com/en/content/learn/superbadges/superbadge_apex
i'm not able to clear the challenge kindly someone help
WarehouseCalloutService:apxc:
public with sharing class WarehouseCalloutService implements Queueable {
private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment';
//class that makes a REST callout to an external warehouse system to get a list of equipment that needs to be updated.
//The callout’s JSON response returns the equipment records that you upsert in Salesforce.
@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);
List<Product2> warehouseEq = new List<Product2>();
if (response.getStatusCode() == 200){
List<Object> jsonResponse = (List<Object>)JSON.deserializeUntyped(response.getBody());
System.debug(response.getBody());
//class maps the following fields: replacement part (always true), cost, current inventory, lifespan, maintenance cycle, and warehouse SKU
//warehouse SKU will be external ID for identifying which equipment records to update within Salesforce
for (Object eq : jsonResponse){
Map<String,Object> mapJson = (Map<String,Object>)eq;
Product2 myEq = new Product2();
myEq.Replacement_Part__c = (Boolean) mapJson.get('replacement');
myEq.Name = (String) mapJson.get('name');
myEq.Maintenance_Cycle__c = (Integer) mapJson.get('maintenanceperiod');
myEq.Lifespan_Months__c = (Integer) mapJson.get('lifespan');
myEq.Cost__c = (Integer) mapJson.get('cost');
myEq.Warehouse_SKU__c = (String) mapJson.get('sku');
myEq.Current_Inventory__c = (Double) mapJson.get('quantity');
myEq.ProductCode = (String) mapJson.get('_id');
warehouseEq.add(myEq);
}
if (warehouseEq.size() > 0){
upsert warehouseEq;
System.debug('Your equipment was synced with the warehouse one');
}
}
}
public static void execute (QueueableContext context){
runWarehouseEquipmentSync();
}
}
anonymous window:
WarehouseCalloutService.runWarehouseEquipmentSync();
https://trailhead.salesforce.com/en/content/learn/superbadges/superbadge_apex
i'm not able to clear the challenge kindly someone help
WarehouseCalloutService:apxc:
public with sharing class WarehouseCalloutService implements Queueable {
private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment';
//class that makes a REST callout to an external warehouse system to get a list of equipment that needs to be updated.
//The callout’s JSON response returns the equipment records that you upsert in Salesforce.
@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);
List<Product2> warehouseEq = new List<Product2>();
if (response.getStatusCode() == 200){
List<Object> jsonResponse = (List<Object>)JSON.deserializeUntyped(response.getBody());
System.debug(response.getBody());
//class maps the following fields: replacement part (always true), cost, current inventory, lifespan, maintenance cycle, and warehouse SKU
//warehouse SKU will be external ID for identifying which equipment records to update within Salesforce
for (Object eq : jsonResponse){
Map<String,Object> mapJson = (Map<String,Object>)eq;
Product2 myEq = new Product2();
myEq.Replacement_Part__c = (Boolean) mapJson.get('replacement');
myEq.Name = (String) mapJson.get('name');
myEq.Maintenance_Cycle__c = (Integer) mapJson.get('maintenanceperiod');
myEq.Lifespan_Months__c = (Integer) mapJson.get('lifespan');
myEq.Cost__c = (Integer) mapJson.get('cost');
myEq.Warehouse_SKU__c = (String) mapJson.get('sku');
myEq.Current_Inventory__c = (Double) mapJson.get('quantity');
myEq.ProductCode = (String) mapJson.get('_id');
warehouseEq.add(myEq);
}
if (warehouseEq.size() > 0){
upsert warehouseEq;
System.debug('Your equipment was synced with the warehouse one');
}
}
}
public static void execute (QueueableContext context){
runWarehouseEquipmentSync();
}
}
anonymous window:
WarehouseCalloutService.runWarehouseEquipmentSync();
Please use below apex class code:-
WarehouseCalloutService if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
anoynous window :
WarehouseCalloutService.runWarehouseEquipmentSync();
Please open the Future method that's you have commented.
After saving the code open execute anonymous window ( CTRl+E ) and run this method :-
System.enqueueJob(new WarehouseCalloutService());
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Trailhead Help (https://trailhead.salesforce.com/en/help?support=home)can provide assistance for situations where Trailhead does not appear to be functioning correctly. You can reach out to them if this is the case.
Thanks!
Please use below code:-
WarehouseCalloutService
After saving the code open execute anonymous window ( CTRl+E ) and run this method :-
System.enqueueJob(new WarehouseCalloutService());
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
I hope your issue has resolved by this solution.
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
warehousecalloutservice:
public with sharing class WarehouseCalloutService implements Queueable, Database.AllowsCallouts {
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;
}
}
}
warehousecalloutserviceMock:
@isTest
global class WarehouseCalloutServiceMock implements HttpCalloutMock {
// implement http mock callout
global static 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;
}
}
warehousecalloutservicetest
@isTest
private class WarehouseCalloutServiceTest {
@isTest
static void testWareHouseCallout(){
Test.startTest();
// implement mock callout test here
Test.setMock(HTTPCalloutMock.class, new WarehouseCalloutServiceMock());
WarehouseCalloutService.runWarehouseEquipmentSync();
System.enqueueJob(new WarehouseCalloutService());
Test.stopTest();
System.assertEquals(1, [SELECT count() FROM Product2]);
}
}
error : Class WarehouseCalloutService must implement the method: void System.Queueable.execute(System.QueueableContext)
Please refer the below forum for the resolution.
https://developer.salesforce.com/forums/?id=906F0000000fzr3IAA