4. Synchronize Salesforce Data With An External System | Apex Specialist Superbadge

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ต.ค. 2024
  • #salesforce #trailhead #codding #superbadge
    Please find the code in comment.
    4th Part Of Apex Specialist Superbadge
    Solution of Synchronize Salesforce Data With An External System of Apex Specialist Superbadge.
    You can ask for solution of any trailhead in comment section.

ความคิดเห็น • 5

  • @apexsalesforcetutorials
    @apexsalesforcetutorials  7 หลายเดือนก่อน +2

    Code:
    Remote Site Name - WarehouseURL
    Remote Site URL - th-superbadge-apex.herokuapp.com
    ******************* WarehouseCalloutService class *********************
    public with sharing class WarehouseCalloutService implements Queueable {
    private static final String WAREHOUSE_URL = '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 warehouseEq = new List();

    if (response.getStatusCode() == 200){
    List jsonResponse = (List)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 mapJson = (Map)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();
    }

    }
    ****************************** Code Runned Under Anonymous Window **************************
    System.enqueue Job (new warehousecallout Service());

  • @hrideshtaldar
    @hrideshtaldar 7 หลายเดือนก่อน +2

    Nice one

  • @HelloWorld-nv4lg
    @HelloWorld-nv4lg 7 หลายเดือนก่อน +2

    Good video