• Urvashi Babbar
  • NEWBIE
  • 19 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 7
    Replies
What are the basic steps to implement ? when do we need JSON?I know many of you posted code , but please explain me the steps in sequence  in order to implement logic.
Hi,
I have a problem with step 2 in Apex Specialist Superbadge. I don't know how I should use field Warehouse_SKU__C as an external ID. This is my method from WarehouseCalloutService class:
@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(response.getStatusCode() == 200) {
            List<Product2> equipmentToSF = new List<Product2>();

            List<WarehouseResponse> equipment = WarehouseResponse.parse(response.getBody());

            for(WarehouseResponse itemFromWH : equipment) {
                Product2 item = new Product2();
                item.Warehouse_SKU__c = itemFromWH.sku;
                item.Name = itemFromWH.name;
                item.Maintenance_Cycle__c = itemFromWH.maintenancePeriod;
                item.Lifespan_Months__c = itemFromWH.lifespan;
                item.Cost__c = itemFromWH.cost;
                item.Current_Inventory__c = itemFromWH.quantity;
                item.Replacement_Part__c = true;

                equipmentToSF.add(item);
            }
            upsert equipmentToSF;

        }
    }
The problem is that every time I call this method, the equipment from external DB is duplicated instead of updated. I try to set Warehouse_SKU__c field as unique but it causes error.
I couldn't find how to use external ID field instead of using standard ID during upserting.

Thank you in advance :)
 
I'm trying to complete the Apex Specialist Superbadge.  I have created my WarehouseCalloutService apex class and it seems to match how others have created their class.  However when I run my code and then try and check the challenge, I'm getting the error that seems many others are getting about the Challenge Not Yet Complete.... "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 endpoint = 'https://th-superbadge-apex.herokuapp.com/equipment';

    @future(callout = true)	//need this so that it knows to call to external source
    public static void runWarehouseEquipmentSync(){
        Http http = new Http();
        HttpRequest httpRequest = new HttpRequest();
        httpRequest.setEndpoint(endpoint);
        httpRequest.setMethod('GET');
        HttpResponse httpResponse = http.send(httpRequest);
        
        //if successfully get the JSON file, need to parse out to different equipment objects
        if (httpResponse.getStatusCode() == 200){ //status = "OK" (this is for GET or HEAD requests)
            List<Object> equipmentList = (List<Object>) JSON.deserializeUntyped(httpResponse.getBody());
            List<Product2> products = new List<Product2>();
            
            for(Object item: equipmentList){
                Map<String, Object> productMap = (Map<String,Object>) item;	//map of item(s) in JSON file
                Product2 product = new Product2();	//list of products to insert/update in system
                
                product.Replacement_Part__c = (Boolean) productMap.get('replacement');
                product.Cost__c = (Integer) productMap.get('cost');                
                product.Current_Inventory__c = (Integer) productMap.get('quantity');
                product.Lifespan_Months__c = (Integer) productMap.get('lifespan');
                product.Maintenance_Cycle__c = (Integer) productMap.get('maintenanceperiod');
                product.Warehouse_SKU__c = (String) productMap.get('sku');
                product.Name = (String) productMap.get('name');
                product.ProductCode = (String) productMap.get('_id');
                products.add(product);
            }
            
            if(products.size() > 0){	//only need to upsert if items actually exist
                System.debug(products);
                upsert products;
            }
        }
    }
}

According to some other strings I have found on this error (https://developer.salesforce.com/forums/?id=906F0000000kE7DIAU), this is what I've looked at and the current status of it:
  • Field Level Security for Lifespan_Months__c field on Equipment (Product2) object: Visible for All profiles
  • User-added image
  • Remote Site Settings: Added this URL as a Remote Site and confirmed it is active - https://th-superbadge-apex.herokuapp.com
  • User-added image
  • Apex Jobs: Confirmed it is listed in Apex Jobs log and that it's listing as a "Future" job type and a "Completed" status.
  • User-added image
  • Execution Log: Confirmed that it shows that 1 of 50 Future classes were executed.
  • User-added image
  • SOQL Query: Confirmed that the job was placed into the system.
  • User-added image

Any assistance as to why I am not getting a complete on this task would be much appreciated!
public class MaintenanceRequestHelper {
    
    Public Static List<Case> oldCase = new List<Case>();
    Public Static List<Case> case1 = [select ID from Case Where status = 'Closed' and Type IN ('Repair', 'Routine Maintenance')];
    Public Static AggregateResult[] minCycleDay2 = [Select min(Equipment__r.Maintenance_Cycle__c) FROM Work_Part__c WHERE Equipment__r.Maintenance_Cycle__c != null
                                         AND Maintenance_Request__c IN: case1];
    
    
    public static void updateWorkOrders(List<Case> closedCase){        
        oldCase = closedCase;
   		List<Case> newCase = new List<Case>();
        
    		for (Case newCase2 : oldCase) {
            			newCase.add(new Case(type = 'Routine Maintenance',
                                status = 'New',
                                origin = 'Web',
                                Subject = null,
                                Date_Reported__c = date.today(),
                                Vehicle__c = newCase2.Vehicle__c,
                                Equipment__c = newCase2.Equipment__c,
                                Date_Due__c = cycleCalc2()));  
        }
       insert newCase;
       
       
     
      
    }
       
    private static Date cycleCalc2() {
        Integer minCycleNum = ((Decimal)minCycleDay2[0].get('expr0')).intValue();
        Date returnDate = Date.today().addDays(Integer.valueOf(minCycleNum));
        return returnDate;
        } 
        
    }
 
@isTest
private class MaintenanceRequestTest {

    @isTest static void TestWithCycleDays() {

        
             Account acct = new Account(Name= 'testAcct');
             insert acct;
             Contact cont = new Contact(LastName = 'contactTest', AccountID = acct.id, email = 'testcont@test.com');
             insert cont;
             Product2 prd1 = new Product2(Name = 'ProductTest1', Maintenance_Cycle__c = 2, Replacement_Part__c = true);
             insert prd1;
             Vehicle__c vhcl1 = new Vehicle__c(Name = 'VehicleTest1');
             insert vhcl1;
             Case MntRequest = new Case(description = 'test123',
                                Subject = 'Other',
                                type = 'Repair',
                                status = 'New',
                                origin = 'Web',
                                Date_Reported__c = date.today(),
                                Vehicle__c = vhcl1.id,
                                Equipment__c = prd1.id,
                                Date_Due__c = date.today(),
                                ContactId = cont.id,
                                AccountId = acct.id); 
        
        insert MntRequest;
        
        Work_Part__c wp1 = new Work_Part__c(Equipment__c = prd1.Id, Maintenance_Request__c = MntRequest.id);
        
        insert wp1;
        
        MntRequest.status = 'Closed';                                    
     
        update MntRequest;
        
        }
    
    @isTest static void testCaseBulkInsert(){
    List<Case> testCaseList = new List<Case>();
        For(Integer i=1 ;i<=300 ; i++) {

            Case MntRequest = new Case(
                                type = 'Routine Maintenance',
                                status = 'Closed',
                                origin = 'Web',
                                Subject = null,
                                Date_Reported__c = date.today(),
                                Vehicle__c = null,
                                Equipment__c = null,
                                Date_Due__c = date.today());
            testCaseList.add(MntRequest);
        }
            system.assertEquals(testCaseList.size(), 300);                   
    } 
    
}
 
trigger MaintenanceRequest on Case (after update, after insert) {
    
    Public List<Case> closedCase = new List<Case>();
    List<Case> caseA = [select ID, vehicle__c, equipment__c, date_due__c from Case Where Id IN :Trigger.new AND status = 'Closed' and Type IN ('Repair', 'Routine Maintenance')];
    for(Case a : caseA) {
        closedCase.add(a);
    }
           MaintenanceRequestHelper.updateWorkOrders(closedCase);  
}

 
I am running into trouble with the "Fulfillment Creation" process builder.

"The Fulfillment Creation process does not appear to be working properly. Please check that your task was created with all of the field values set appropriately."

I have the following mapping and cannot figure out which field is not being set properly.

CREATE A RECORD  - Task

Assigned to ID - OpportunityLineItem.Opportunity.OwnerId
Priority - Normal
Status - Not Started 
Subject - Update explorer
Related to ID - OpportunityLineItem.Opportunity.Id

This action is in the second node of my PB which has criteria:

OpportunityLineItem.Explorer__c is null True

Can anyone provide help with this i
Hello,

For this superbadge in the given entity relation diagram there is no connection that depicts the direct relation between Maintenance Request (case) and Equipment (Product). It is very confusing looking at the diagram given to understand this. Earlier in my solution to challenge 1 I assumed that there is no direct relation between the said objects and that I need to access the Equipment data by traversing the junction object (Work Part). Solution became much simpler when I swa that there is already a direct relation between Maintenance Request (case) and Equipment (Product).
Please look into this. Correct me I am wrong. Thank you.

 User-added image