• Prasanth R
  • NEWBIE
  • 35 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 16
    Replies
I'm not able to clear the challenge ,kindly help me to pass  the challenge .Below i adding my code
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]);
    }     
}

User-added image
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
 
initially it showed the variable doesn't exist error  cloned case id(line 18) i created a new field in cloned case id(lookup relationship with equipment) in maintenancerequest(case) object.
trigger:
trigger MaintenanceRequest on Case (before update, after update) {
    if(Trigger.isAfter) MaintenanceRequestHelper.updateWorkOrders(Trigger.New);
}
class:
public with sharing class MaintenanceRequestHelper {
    public static void updateWorkOrders(List<Case> caseList) {
        List<case> newCases = new List<Case>();
        Map<String,Integer> result=getDueDate(caseList);
        list<Equipment_Maintenance_Item__c> itemsListToinsert= new list<Equipment_Maintenance_Item__c>();
      Map<String,list<Equipment_Maintenance_Item__c>> resultItmes=getMaintainanceItems(caseList);
        for(Case c : caseList){
            if(c.status=='closed')
                if(c.type=='Repair' || c.type=='Routine Maintenance'){
                    Case newCase = new Case();
                    newCase.Status='New';
                    newCase.Origin='web';
                    newCase.Type='Routine Maintenance';
                    newCase.Subject='Routine Maintenance of Vehicle';
                    newCase.Vehicle__c=c.Vehicle__c;
                    newCase.Equipment__c=c.Equipment__c;
                    newCase.Date_Reported__c=Date.today();
                    newcase.Cloned_Case_Id__c=c.Id;
                    if(result.get(c.Id)!=null)
                     newCase.Date_Due__c=Date.today()+result.get(c.Id);
                    else
                        newCase.Date_Due__c=Date.today();
                    newCases.add(newCase);
                }
        }        
       if(newCases.size()>0)
       {      
           insert newCases; 
           
           for(Case c : newCases){
             List<Equipment_Maintenance_Item__c> temp =  resultItmes.get(c.Cloned_Case_Id__c);
               if(temp !=null){
                    for(Equipment_Maintenance_Item__c row:temp){
                    Equipment_Maintenance_Item__c newitem = new Equipment_Maintenance_Item__c();
                        newitem.Equipment__c=row.Equipment__c;
                        newitem.Maintenance_Request__c= c.Id;
                        newitem.Quantity__c= row.Quantity__c;  
                        itemsListToinsert.add(newitem);
                        
                    }
               }
               
           }
           
           
       }
        
       if(itemsListToinsert.size()>0)
           insert itemsListToinsert;
    }
    //
    public static  Map<String,Integer> getDueDate(List<case> CaseIDs){       
       Map<String,Integer> result = new Map<String,Integer>();
        Map<Id, case> caseKeys = new Map<Id, case> (CaseIDs);        
       List<AggregateResult> wpc=[select Maintenance_Request__r.ID cID,min(Equipment__r.Maintenance_Cycle__c)cycle
                      from Equipment_Maintenance_Item__c where  Maintenance_Request__r.ID in :caseKeys.keySet() and Equipment__r.Maintenance_Cycle__c != null group by             Maintenance_Request__r.ID ];
        for(AggregateResult res :wpc){
            Integer addDays=0;
            if(res.get('cycle')!=null)
                addDays+=Integer.valueOf(res.get('cycle'));
            result.put((String)res.get('cID'),addDays);
        }
        return result;
}
    
    
     public static Map<String,list<Equipment_Maintenance_Item__c>> getMaintainanceItems(List<case> CaseIDs){       
     
       Map<String,list<Equipment_Maintenance_Item__c>> mapofMaintainanceItems = new Map<String,list<Equipment_Maintenance_Item__c>>();
        Map<Id, case> caseKeys = new Map<Id, case> (CaseIDs);        
       list<Equipment_Maintenance_Item__c> lstrec = new  list<Equipment_Maintenance_Item__c>([select id ,Maintenance_Request__c,Equipment__c,Quantity__c  
                      from Equipment_Maintenance_Item__c where  Maintenance_Request__r.ID in :caseKeys.keySet() ]);
        
         for(Equipment_Maintenance_Item__c row:lstrec){
              
                if (mapofMaintainanceItems.containsKey(row.Maintenance_Request__c)) {
                    List<Equipment_Maintenance_Item__c> temp = mapofMaintainanceItems.get(row.Maintenance_Request__c);
                        temp.add(row);
                    mapofMaintainanceItems.put(row.Maintenance_Request__c, temp);
                }
                else{
                    mapofMaintainanceItems.put(row.Maintenance_Request__c, new List<Equipment_Maintenance_Item__c> { row });
                }    
                       
         }
         
        return mapofMaintainanceItems;
}
}
    
User-added imageUser-added image
i'm beginner in trigger.i tried below code but stucked in midway..kindly someone help

trigger practiceacc on Account (after update){
    List<contact> ctlt = new List<contact>();
    set<Id> st = new set<Id>();
    for(Account acc:Trigger.new){
        st.add(acc.id);       
    }
Map<Id,Account> mapacc = new new Map<Id,Account>([Select Id,Name,Phone from contact where AccountId in:st]);
    for(Account obj1:Trigger.new){
      if(mapacc.get(obj1.Accountid).obj1=Phone)  
    }     
    update ctlt;
}
In diagnosis object created a field (causes-datatype(picklist)--fever,cough,wheezing. and in patient object created a field is called Reason(datatype-reason):My requirement : if causes is fever,it will pop up on reason as fever,if it cough reason should be cough..i don;t know how to write a code..kindly someone help me.User-added imageUser-added imageUser-added image
scenario:If the category is covid,insurance should true,
i try the below code it running without error but the insurance field is not active..kindly someone help me.below i added the codes and screenshot.

kindly someone give the correct code.
User-added imageUser-added imageUser-added image
i'm trying to generate the invoice using visual force but getting this error System.QueryException: List has more than 1 row for assignment to SObject..kindly someone assist me.below i mention the code

apex class:

global with sharing class CustomerController {
    
    public Customer__c cust {get;set; }
    
    public CustomerController(){
        cust = [Select Name,
                Delivery_Address__c,
                Phone__c,
                Product_cost__c,
                Product_Name__c,
                Delivery_cost__c,
                Total_cost__c
                from Customer__c];
    }
}


VF page:
<apex:page Controller="CustomerController">
        <apex:pageBlock >
          <apex:pageBlockSection title="Invoice">
             <apex:outputText value="{!cust.Name}"/><br/>
             <apex:outputText value="{!cust.Delivery_Address__c}"/><br/>
             <apex:outputText value="{!cust.Phone__c}"/><br/>
             <apex:outputText value="{!cust.Product_cost__c}"/><br/>
             <apex:outputText value="{!cust.Product_Name__c}"/><br/>
             <apex:outputText value="{!cust.Delivery_cost__c}"/><br/> 
              <apex:outputText value="{!cust.Total_cost__c}"/><br/> 
           </apex:pageBlockSection>
        </apex:pageBlock>
</apex:page>

User-added image
  i'm not able to authorize the dev hub.It's taking long time to load.when i authorize in someother way using this command sfdx force:auth:device:login....it's unable to create defaut scratch org.Kindly someone help me.Below i mentioned the trailhead link

https://trailhead.salesforce.com/content/learn/projects/set-up-your-lightning-web-components-developer-tools/create-a-lightning-web-component?trail_id=build-lightning-web-components
hi folks,
     In visualstuidocode.I created the project and i tried to authorize with org..the new tab opened and i entered the playground credentials it didn't open.it's loading longtime.how to fix this?kindly assit me
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'm beginner in trigger.i tried below code but stucked in midway..kindly someone help

trigger practiceacc on Account (after update){
    List<contact> ctlt = new List<contact>();
    set<Id> st = new set<Id>();
    for(Account acc:Trigger.new){
        st.add(acc.id);       
    }
Map<Id,Account> mapacc = new new Map<Id,Account>([Select Id,Name,Phone from contact where AccountId in:st]);
    for(Account obj1:Trigger.new){
      if(mapacc.get(obj1.Accountid).obj1=Phone)  
    }     
    update ctlt;
}
In diagnosis object created a field (causes-datatype(picklist)--fever,cough,wheezing. and in patient object created a field is called Reason(datatype-reason):My requirement : if causes is fever,it will pop up on reason as fever,if it cough reason should be cough..i don;t know how to write a code..kindly someone help me.User-added imageUser-added imageUser-added image
scenario:If the category is covid,insurance should true,
i try the below code it running without error but the insurance field is not active..kindly someone help me.below i added the codes and screenshot.

kindly someone give the correct code.
User-added imageUser-added imageUser-added image
i'm trying to generate the invoice using visual force but getting this error System.QueryException: List has more than 1 row for assignment to SObject..kindly someone assist me.below i mention the code

apex class:

global with sharing class CustomerController {
    
    public Customer__c cust {get;set; }
    
    public CustomerController(){
        cust = [Select Name,
                Delivery_Address__c,
                Phone__c,
                Product_cost__c,
                Product_Name__c,
                Delivery_cost__c,
                Total_cost__c
                from Customer__c];
    }
}


VF page:
<apex:page Controller="CustomerController">
        <apex:pageBlock >
          <apex:pageBlockSection title="Invoice">
             <apex:outputText value="{!cust.Name}"/><br/>
             <apex:outputText value="{!cust.Delivery_Address__c}"/><br/>
             <apex:outputText value="{!cust.Phone__c}"/><br/>
             <apex:outputText value="{!cust.Product_cost__c}"/><br/>
             <apex:outputText value="{!cust.Product_Name__c}"/><br/>
             <apex:outputText value="{!cust.Delivery_cost__c}"/><br/> 
              <apex:outputText value="{!cust.Total_cost__c}"/><br/> 
           </apex:pageBlockSection>
        </apex:pageBlock>
</apex:page>

User-added image
  i'm not able to authorize the dev hub.It's taking long time to load.when i authorize in someother way using this command sfdx force:auth:device:login....it's unable to create defaut scratch org.Kindly someone help me.Below i mentioned the trailhead link

https://trailhead.salesforce.com/content/learn/projects/set-up-your-lightning-web-components-developer-tools/create-a-lightning-web-component?trail_id=build-lightning-web-components
hi folks,
     In visualstuidocode.I created the project and i tried to authorize with org..the new tab opened and i entered the playground credentials it didn't open.it's loading longtime.how to fix this?kindly assit me