Apex Specialist

Apex Specialist

Pre-work and Notes

👉Create a new Trailhead Playground for this superbadge. Using this org for any other reason might create problems when validating the challenge.

👉Install this unmanaged package. This package contains all schema and shells for Apex logic needed to complete this challenge. The only changes you need to make to the data schema are renaming the standard objects or modifying standard fields per the Entity Diagram. If you have trouble installing a managed or unmanaged package or app from AppExchange, follow the steps in this article.

👉Use the naming conventions specified in the requirements document to ensure a successful deployment.

👉Review the data schema in your modified Salesforce org as you read the detailed requirements below.

Create New Trailhead Play Ground.
After Successfull creation of New Playground, Launch the Play Ground.
Click on Setup - Users - Select Checkbox beside your User Name & Copy the User Id.
Click on RESET Password.
Reset your Password on clicking the LINK Received to your Email, Create New Password.

Logout From the Current Play Ground.
From Trailhead click on the Link Provided to Install the Package, It will redirect to Login Page
Login with the User Id you have copied earlier and Enter Password then it will Allow you to redirect to Trailhead Playground.
STEP 1 : Install Unmanaged Package From the Below URL
https://login.salesforce.com/?ec=302&startURL=%2Fpackaging%2FinstallPackage.apexp%3Fp0%3D04t36000000i5UM

STEP 2 : Select Install For ADMIN Only.

Challenge #1 : Automate Record Creation

Standard Objects:-
You’ll be working with the following standard objects:
Maintenance Request (renamed Case): Service requests for broken vehicles, malfunctions, and routine maintenance.
Equipment (renamed Product): Items in the warehouse used to fix or maintain RVs. Repair parts have a flag indicating that they are for repair.

Custom Objects:-
Vehicle: Vehicles in HowWeRoll’s rental fleet. These records contain all stock parts that will eventually need replacement or maintenance.
Work Part: Equipment used for a maintenance request.

Entity Diagram:-

Case Page Layout:-
Case Page Layout Assignment:-
Product Page Layout:-
Product Page Layout Assignment:-

Challenge #4 : Test Automation Logic

Build tests for all cases (positive, negative, and bulk) specified in the business requirements. You must have 100% test coverage to pass this section and assert values to prove that your logic is working as expected. Choose Run All tests in the Developer Console at least once before attempting to submit this section. Be patient as it may take 10-20 seconds to process the challenge check.

 @IsTest  
 public class TestDataFactory {  
   public static List<Case> createMaintenanceRequest(string requestType, integer totalNumber) {  
     List<Case> mtnRequests = new List<Case>();  
     if (totalNumber >0 && requestType.length()>0 ){  
       //create Veichle  
       Vehicle__c v = new Vehicle__c(Name='TestVehicle 01', VIN_Number__c='aqwepnvaore2424');  
       insert v;  
       //create Equipments: two with different maintenance cycles  
       List<Product2> prods = new List<Product2>();  
       prods.add(new Product2(Name='TestProduct 01', Warehouse_SKU__c='200001', Lifespan_Months__c=12, Maintenance_Cycle__c=60, Replacement_Part__c=true));  
       prods.add(new Product2(Name='TestProduct 02', Warehouse_SKU__c='200002', Lifespan_Months__c=24, Maintenance_Cycle__c=30, Replacement_Part__c=true));  
       insert prods;   
       //create maintenance requests  
       for (integer i = 0; i<totalNumber; i++) {  
         mtnRequests.add(new Case(Type = requestType, Status='New', Origin='Phone', Equipment__c=prods[0].id, Subject='Test Case'));  
       }  
       insert mtnRequests;  
       //Add two work parts for each maintenance request created  
       List<Work_Part__c> wps = new List<Work_Part__c>();  
       for (Case c: mtnRequests) {  
         wps.add(new Work_Part__c(Equipment__c=prods[0].id, Maintenance_Request__c=c.id, Quantity__c=1));  
         wps.add(new Work_Part__c(Equipment__c=prods[1].id, Maintenance_Request__c=c.id, Quantity__c=2));  
       }  
       insert wps;  
     }    
     return mtnRequests;  
   }  
 }  

 @IsTest  
 public class MaintenanceRequestTest {  
   @IsTest  
   static void TestPositiveSingle() {  
     //Test Repair maintance request  
     testMaintenanceRequestAutomation('Repair', 1, 'Closed');  
     //Test Routin Maintenance request  
     testMaintenanceRequestAutomation('Routine Maintenance', 1, 'Closed');  
   }  
   @IsTest  
   static void TestNegativeSingle() {  
     //Test Other maintance request  
     testMaintenanceRequestAutomation('Other', 1, 'Closed');  
     //Test Repair maintance request  
     testMaintenanceRequestAutomation('Repair', 1, 'Working');  
     //Test Routin Maintenance request  
     testMaintenanceRequestAutomation('Routine Maintenance', 1, 'Escalated');  
   }  
   @IsTest  
   static void TestPositiveBulk() {  
     //Test Repair maintance request  
     testMaintenanceRequestAutomation('Routine Maintenance', 300, 'Closed');  
     //Test Repair maintance request  
     testMaintenanceRequestAutomation('Repair', 300, 'Closed');  
   }  
   @IsTest  
   static void TestNegativeBulk() {  
     //Test Other maintance request  
     testMaintenanceRequestAutomation('Other', 300, 'Closed');  
     //Test Repair maintance request  
     testMaintenanceRequestAutomation('Repair', 300, 'Working');  
     //Test Routin Maintenance request  
     testMaintenanceRequestAutomation('Routine Maintenance', 300, 'Escalated');  
   }  
   private static void testMaintenanceRequestAutomation(string requestType, integer totalCount, string newStatus) {  
     //Test Repair maintance request  
     List<Case> testRequests = TestDataFactory.createMaintenanceRequest(requestType, totalCount);  
     for (Case tr: testRequests) {  
       tr.Status = newStatus;  
     }  
     update testRequests;  
     List<Case> newFollowupRequests = [SELECT id, Type, Status, Vehicle__c, Equipment__c, Subject, Origin, Date_Reported__c, Date_Due__c  
                      FROM Case WHERE ParentId IN: testRequests   
                      AND Status = 'New'];  
     integer expectedTotal = 0;  
     if(newStatus == 'Closed' && (requestType =='Repair' || requestType == 'Routine Maintenance')) {  
       expectedTotal = totalCount;  
     }  
     // System.assertEquals(expectedTotal,newFollowupRequests.size());  
     if (expectedTotal>0) {  
       for (Case newFollowupRequest: newFollowupRequests) {  
         System.assertEquals('Routine Maintenance', newFollowupRequest.Type);  
         System.assertEquals('System Generated Routine Maintenance', newFollowupRequest.Subject);  
         System.assertEquals('System', newFollowupRequest.Origin);  
         System.assertEquals(Date.today(), newFollowupRequest.Date_Reported__c);  
         System.assertEquals(Date.today().addDays(30), newFollowupRequest.Date_Due__c);  
       }  
     }  
   }  
 }  

Challenge #5 : Test Callout Logic

Build tests for your callout using the included stubs for the callout mock (WarehouseCalloutServiceMock) and callout test class (WarehouseCalloutServiceTest) in the package. You must have 100% test coverage to pass this challenge and assert values to prove that your logic is working as expected.

 @isTest  
 private class WarehouseCalloutServiceTest {  
  // implement your mock callout test here  
   @isTest  
   static void WarehouseEquipmentSync(){  
     Test.startTest();  
     // Set mock callout class   
     Test.setMock(HttpCalloutMock.class, new WarehouseCalloutServiceMock());   
     // This causes a fake response to be sent from the class that implements HttpCalloutMock.   
     WarehouseCalloutService.runWarehouseEquipmentSync();  
     Test.stopTest();    
     //System.assertEquals(1, [SELECT count() FROM Product2]);      
   }  
 }  

Challenge #6 : Test Scheduling Logic

Build tests for your scheduled logic using the included stubs for your scheduled class (WarehouseSyncSchedule) in the package. You must have 100% test coverage to pass this challenge and assert values to prove that your logic is working as expected.

 @isTest  
 public class WarehouseSyncScheduleTest{  
   @isTest  
   static void testWarehouseSyncSchd(){  
     String sch = '0 0 0 * * ? 2020';  
     Test.startTest();  
       // Set mock callout class  
       Test.setMock(HttpCalloutMock.class, new WarehouseCalloutServiceMock());  
       String jobId = System.schedule('ScheduledWarehouseTest', sch, new WarehouseSyncSchedule());  
       CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE Id = :jobId];  
       System.assertEquals(sch, ct.CronExpression);  
     Test.stopTest();  
   }  
 }