You need to sign in to do that
Don't have an account?
Jennifer BERNARD
Apex Specialist 3rd challenge: Synchronize Salesforce data with an external system
Hello everyone. I can't validate Synchronize Salesforce data with an external system super badge challenge and I don't know why. I get this error after trying to validate it:
I've also ran this query to make sure it worked:
Challenge Not yet complete... here's what's wrong: The WarehouseCalloutService class does not appear to have run successfully as the equipment records are not found in the database. The REST endpoint returns 22 records so your org should have at least 22 records in the Product2 table. Make sure that you successfully 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.Here's my code:
public with sharing class WarehouseCalloutService implements Queueable, Database.AllowsCallouts { private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment'; /** * Queue process execution */ public static void execute(QueueableContext context){ syncWarehouseAndSalesforceDB(); } /** * Synchronize Warehouse Data to Salesforce database. */ public static void syncWarehouseAndSalesforceDB() { // Send GET request to Heroku Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint(WAREHOUSE_URL); request.setMethod('GET'); HttpResponse response = http.send(request); if (response.getStatusCode() == 200) { // Get request result body List<Object> results = (List<Object>) JSON.deserializeUntyped(response.getBody()); // Create equipments to insert List<Product2> equipmentsToInsertList = new List<Product2>(); for (Object equipment :results) { // Parse object to String, Value map Map<String, Object> equipmentMap = (Map<String, Object>) equipment; Product2 equipmentToInsert = new Product2( Cost__c = (Decimal) equipmentMap.get('cost'), Lifespan_Months__c = (Integer) equipmentMap.get('getlifespan'), Maintenance_Cycle__c = (Integer) equipmentMap.get('maintenanceperiod'), Name = (String) equipmentMap.get('name'), Current_Inventory__c = (Integer) equipmentMap.get('quantity'), Replacement_Part__c = (Boolean) equipmentMap.get('replacement'), Warehouse_SKU__c = (String) equipmentMap.get('sku') ); equipmentsToInsertList.add(equipmentToInsert); } System.debug(equipmentsToInsertList); // upsert equipment upsert equipmentsToInsertList Warehouse_SKU__c; } } }I ran this code in Execute Anonymous Window:
System.enqueueJob(new WarehouseCalloutService());The jobs appears in the Apex Job list, it successfully ran.
I've also ran this query to make sure it worked:
// return 22 records found SELECT COUNT() FROM Product2
The tests also run successfully.
I've also checked that I am using the correct Playground environment for the validation.
Could someone explain to me what's wrong ?
Please note that Questions about how to pass Trailhead challenges are not on topic, because these challenges are intended to be independent demonstrations of your abilities.
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.
Please close the thread by selected as Best Answer so that we can keep our community clean
Thanks,