/** * ─────────────────────────────────────────────────────────────────────────────────────────────────┐ * This web service class is use for handle Shopify's Location webhook response. * Trigger on Location update. * Shopify API Documentation: https://shopify.dev/docs/admin-api/rest/reference * Create Shopify Store: https://www.shopify.com/signup?itcat=identity&itterm=create-new-store * Shopify API Release 2020: https://www.shopify.in/partners/blog/shopify-api-release-january-2020 * What is Person Account in Salesforce ? https://help.salesforce.com/articleView?id=account_person.htm&type=5 * ────────────────────────────────────────────────────────────────────────────────────────────────── * @author Sumit * ────────────────────────────────────────────────────────────────────────────────────────────────── */ @RestResource(UrlMapping='/UpdateLocationFromShopify/*') global with sharing class UpdateLocationFromShopify { @HTTPPost global static void updatelocation(){ Restrequest request = restContext.request; String companyTimeZone = [SELECT Id, TimeZoneSidKey FROM Organization Limit 1][0].TimeZoneSidKey; String store = 'Default'; Map params = request.params; if(!params.isEmpty() && params.containsKey('store') && params.get('store') != null) store = params.get('store'); Restresponse response = restContext.response; String JSONResponseBody = request.requestBody.ToString().Trim(); if(JSONResponseBody == '' || JSONResponseBody == null) return; list listofConfiguration = new list(); String query = 'Select '+CheckAccessibility.isAccessible('id,name,HIC_ShopifySync__Default_Field_Mapping__c,HIC_ShopifySync__Batch_Is_Processing__c,HIC_ShopifySync__Specify_Close_Date__c, HIC_ShopifySync__Account_Contact__c, HIC_ShopifySync__Person_Account__c, HIC_ShopifySync__Default_Account__c, HIC_ShopifySync__Shopify_URL__c, HIC_ShopifySync__API_Key__c, HIC_ShopifySync__Private_Key_Password__c, HIC_ShopifySync__Opportunity__c, HIC_ShopifySync__Order__c, HIC_ShopifySync__Opportunity_Line_Item__c, HIC_ShopifySync__Order_Line_Item__c, HIC_ShopifySync__Order_Fulfillment__c','HIC_ShopifySync__HIC_Configuration__c')+' from HIC_ShopifySync__HIC_Configuration__c where '+CheckAccessibility.isAccessible('HIC_ShopifySync__Store__c', 'HIC_ShopifySync__HIC_Configuration__c')+' = \''+store+'\' LIMIT 49999'; listofConfiguration = database.query(query); Map Main = (Map) JSON.deserializeUntyped(JSONResponseBody); list listoflocationfieldmapping = new list(); query = 'Select '+CheckAccessibility.isAccessible('HIC_ShopifySync__SF_Field__c, HIC_ShopifySync__Shopify_Fields__c, HIC_ShopifySync__Nested__c , HIC_ShopifySync__IsSFID__c, HIC_ShopifySync__Default_Value__c, HIC_ShopifySync__Is_Override__c ','HIC_ShopifySync__HIC_Field_Mapping__c')+' from HIC_ShopifySync__HIC_Field_Mapping__c Where '+CheckAccessibility.isAccessible('HIC_ShopifySync__Object_Name__c','HIC_ShopifySync__HIC_Field_Mapping__c')+' = \'HIC_ShopifySync__Location__c\' AND '+CheckAccessibility.isAccessible('HIC_ShopifySync__Store__c','HIC_ShopifySync__HIC_Field_Mapping__c')+' = \''+store+'\' LIMIT 49999'; listoflocationfieldmapping = database.query(query); String listType1 = 'List<' + 'HIC_ShopifySync__Location__c' + '>'; list LoactionListToupsert = (List)Type.forName(listType1).newInstance(); LoactionListToupsert.add(HIC_ShopifyUtility.processFieldTypeAndMapping(listoflocationfieldmapping,'HIC_ShopifySync__Location__c',Main,listofConfiguration,companyTimeZone)); if(LoactionListToupsert.Isempty()) return; Schema.SObjectType objectType1 = Schema.getGlobalDescribe().get('HIC_ShopifySync__Location__c'); Map fieldMap1 = objectType1.getDescribe().fields.getMap(); Schema.SobjectField theField1 = fieldMap1.get('HIC_ShopifySync__Shopify_Id__c'); try{ if(!Test.isRunningTest()){ EmailErrorCSV.makeCsvAndSendInEmail(JSONResponseBody,'HIC_ShopifySync__Location__c',LoactionListToupsert,theField1,true,store); return ; } }catch(Exception e){ System.debug('Exception '+ e.getMessage() + ' at' +e.getLineNumber()); } } }