top of page
Search

Example of a Car Service Facility in Salesforce

  • abhyash
  • Mar 11, 2023
  • 3 min read

Submitted By: Abhyash Timsina - https://www.linkedin.com/in/abhyashtimsina/

Date: 31/10/2022


Use Case: To provide the finest customer service and have a complete picture of their history, it is necessary to manage a service center's business process.


1. A new vehicle is reserved for a service with a specific date (a reservation record should be produced).






2. A work order connected to the vehicle and the reservation was automatically created when the reservation's status changed to "Present".






3. The mechanic can add essential spare parts connected to the work order and send -change status "Check Warehouse"- to the warehouse.


4. Once submitted, confirm whether the parts are still available at the current warehouse.


5. Create an order with line items for unavailable products if the parts are not readily available.







6. To update the items, press the "Update Inventory" button in the order object, which will contact an API and use the sku as an external field.


Note: Remote Site added for 'https://th-superbadge-apex.herokuapp.com

/** * Created by Abhyash Timsina on 31/10/2022. */ public class VehicleServiceCenter { public class WebsiteAPIData { public Id id; public Boolean replacement; public Integer quantity; public String name; public Integer maintenanceperiod; public Integer lifespan; public Integer cost; public Integer sku; } public class FlowInput { @InvocableVariable(Label='Order Items' Description='Order Items' Required=true) public List<OrderItem> orderItems; } @InvocableMethod(Label='Update Quantity On Order Items' Description='Update Quantity On Order Items') public static void getAPIData(List<FlowInput> params) { for ( FlowInput param : params ) { List<WebsiteAPIData> response = new List<WebsiteAPIData>(); try { HttpRequest req = new HttpRequest(); HttpResponse res = new HttpResponse(); Http http = new Http(); req.setHeader('Content-Type', 'application/json'); req.setHeader('X-Accept-Version', '2.0.0'); req.setEndpoint('https://th-superbadge-apex.herokuapp.com/equipment?_ga=2.189647147.180816799.1665808863-921858111.1665493384'); req.setMethod('GET'); res = http.send(req); response = (List<WebsiteAPIData>) JSON.deserialize(res.getBody(), List<WebsiteAPIData>.class); System.debug(response); System.debug('Str:' + res.getBody()); for (WebsiteAPIData wad : response) { for (OrderItem oi : param.orderItems) { if (wad.sku == oi.Product_Sku__c) { oi.Quantity = wad.quantity; } } } update param.orderItems; } catch (Exception e) { System.debug('Error:' + e.getMessage() + 'LN:' + e.getLineNumber()); } } } }


7. The vehicle object should have a drop-down list for the vehicle make. As part of expansion plans, the manager must add new manufacturers to the list; however, she prefers to create new records (in the object Vehicle Makes) and set the value instead of going to the object to change the picklist values. It is our responsibility to update the drop-down menu once new records are added to this object.




Data model





List of spare components (upload using any method): - I used data loader to load this to Spare_Parts__c using mapping fields on top column



Task Prerequisites & Assumptions:

· Suppose the data model's necessary fields that will let it fulfill the need.












· Create Test classes if needed


/** * Created by Abhyash Timsina on 31/10/2022. */ @IsTest(SeeAllData = true) private class VehicleServiceCenterTest { @IsTest static void getQuantityTest() { Product2 p = new Product2(Name='Cooling Tower', StockKeepingUnit = '1000180', IsActive = true); insert p; PricebookEntry pbe = new PricebookEntry( Product2Id = p.Id, UnitPrice = 10000, IsActive = true,UseStandardPrice = false, Pricebook2Id = System.Test.getStandardPricebookId()); insert pbe; Account a = new Account(Name='Test Account'); insert a; Order o = new Order(Name='Test Order', AccountId = a.Id, Pricebook2Id = System.Test.getStandardPricebookId(), EffectiveDate = System.today(), Status = 'Draft'); insert o; OrderItem oi = new OrderItem(OrderId = o.Id, Quantity = 1, UnitPrice = 10000, PricebookEntryId = pbe.Id); insert oi; List<OrderItem> orderItems = new List<OrderItem>(); orderItems.add(oi); System.Test.startTest(); Map<String,String> headers = new Map<String, String>(); headers.put('Content-Type','application/json'); headers.put('X-Accept-Version','2.0.0'); System.Test.setMock(HttpCalloutMock.class, new VehicleServiceCenterMock(200,'Success','[{"_id":"55d66226726b611100aaf750","replacement":false,"quantity":2,"name":"Cooling Tower","maintenanceperiod":365,"lifespan":120,"cost":10000,"sku":"1000180"}]',headers)); VehicleServiceCenter.FlowInput orderItemFlowInput = new VehicleServiceCenter.FlowInput(); orderItemFlowInput.orderItems = orderItems; VehicleServiceCenter.getAPIData(new List<VehicleServiceCenter.FlowInput>{orderItemFlowInput}); System.Test.stopTest(); System.assertEquals(2, oi.Quantity); } }


· Display related tabs only on the app



 
 
 

Comments


bottom of page