Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adrianmi8/a1e2fac59437aef642382e47a6ca1a32 to your computer and use it in GitHub Desktop.
Save adrianmi8/a1e2fac59437aef642382e47a6ca1a32 to your computer and use it in GitHub Desktop.
Zenkraft - Create Shipment from Account Object via Trigger - FedexQueuedShipmentStatusTriggerHandler
public class FedexQueuedShipmentStatusTriggerHandler {
public static Boolean enableTrigger = true;
public static void updateValidationIfError(Map<Id, zkfedex__QueuedShipmentStatus__c> newMap) {
Set<Id> errorsSet = new Set<Id>();
Boolean isContinue = false;
for (zkfedex__QueuedShipmentStatus__c qss : newMap.values()) {
if (qss.zkfedex__Status__c == 'ERROR') {
errorsSet.add(qss.Id);
}
}
Map<Id, zkfedex__QueuedShipmentStatus__c> errorsMap = new Map<Id, zkfedex__QueuedShipmentStatus__c>([
SELECT zkfedex__StatusMessage__c, zkfedex__QueuedShipment__r.zkfedex__Account__c
FROM zkfedex__QueuedShipmentStatus__c
WHERE Id IN :errorsSet]);
List<Zenkraft_Validation_Error__c> validationList = new List<Zenkraft_Validation_Error__c>();
for (zkfedex__QueuedShipmentStatus__c qss : errorsMap.values()) {
Id accountId = Id.valueOf(qss.zkfedex__QueuedShipment__r.zkfedex__Account__c);
validationList.add(
new Zenkraft_Validation_Error__c(
Error_Text__c = 'FedEx: ' + qss.zkfedex__StatusMessage__c,
Account__c = accountId));
}
if ( ! validationList.isEmpty()) {
insert validationList;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment