global with sharing class UtilityPro { global static void addWebhookMapping(String name, String upsertURL, String deleteURL, Boolean activated) { List webhookUrlMappingList = new List(); HIC_ShopifySync__WebhookURlMapping__c newMapping = new HIC_ShopifySync__WebhookURlMapping__c( Name = name, HIC_ShopifySync__UpsertURL__c = upsertURL, HIC_ShopifySync__DeleteURL__c = deleteURL, HIC_ShopifySync__Activated__c = activated ); webhookUrlMappingList.add(newMapping); if (!webhookUrlMappingList.isEmpty()) { try { List existingMappings = [ SELECT Id FROM HIC_ShopifySync__WebhookURlMapping__c WHERE Name = :name ]; if (existingMappings.isEmpty()) { insert webhookUrlMappingList; } else { for (HIC_ShopifySync__WebhookURlMapping__c existingMapping : existingMappings) { existingMapping.HIC_ShopifySync__UpsertURL__c = upsertURL; existingMapping.HIC_ShopifySync__DeleteURL__c = deleteURL; existingMapping.HIC_ShopifySync__Activated__c = activated; } update existingMappings; } } catch (DmlException e) { System.debug('An error occurred while upserting webhook URL mappings: ' + e.getMessage()); } } } }