• Pankaj Kumar Maurya
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
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();
User-added imageUser-added image
 
i had populate all the objects name in the org by using "iteration"    then my requirement is whenever i onclick any object  i need to display all fields related to that object  pls anyone help mei got the all the object names like these
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.

here is my code

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 Warehouse_SKU__c;
        
        }
        
       
    }
}
I have a SOQL query which works fine:
SELECT Id, Name, (SELECT Id,Name FROM Contacts)
                    FROM Account
                    WHERE Name = 'Apollo'

But the following queries, which have been similarly formed as the above, do not run:
SELECT Id, Candidate_Name__c, (SELECT Id,Assessment__c FROM Review__c)
                         FROM Job_Application__c
                         WHERE Candidate_Name__c = 'Jamie Sandras'
Error: "Didn't understand relationship 'Review__c' in FROM part of query call...."
 
SELECT Id, Candidate_Name__c, (SELECT Id,Assessment__c FROM Review__r)
                         FROM Job_Application__c
                         WHERE Candidate_Name__c = 'Jamie Sandras'
Error: "Didn't understand relationship 'Review__r' in FROM part of query call...."

where Review__c is child object of Job_Application__c


So I have 2 questions:

1. Is it a limitation that such queries (with sub-queries to child object) work only for standard objects and not for custom objects?

2. In the first query, why does the sub-query uses the object name "Contacts" and not "Contact" which is the actual object name?
SELECT Id, Name, (SELECT Id,Name FROM Contacts) FROM Account ....
  • December 30, 2016
  • Like
  • 0