fork download
  1. public class StageProcessingHandler {
  2. public static void processStaging(List<StageRecord__c> incomingRecords) {
  3. // Ensure processing if there are records to avoid unnecessary queries/calculations
  4. if (incomingRecords == null || incomingRecords.isEmpty()) {
  5. return;
  6. }
  7.  
  8. Map<Id, StageRecord__c> currentDataMap = new Map<Id, StageRecord__c>();
  9. Map<String, StageRecord__c> freshDataMap = new Map<String, StageRecord__c>();
  10.  
  11. // Divide incoming records into respective maps based on LinkID__c or MortgageID__c
  12. for (StageRecord__c record : incomingRecords) {
  13. if (record.LinkID__c != null) {
  14. currentDataMap.put(record.LinkID__c, record);
  15. } else if (record.MortgageID__c != null) {
  16. freshDataMap.put(record.MortgageID__c, record);
  17. }
  18. }
  19.  
  20. // Skip if there is no fresh data to process
  21. if (freshDataMap.isEmpty()) {
  22. return;
  23. }
  24.  
  25. // Retrieve matching deals from the database
  26. Map<Id, Deal> dealMap = new Map<Id, Deal>([
  27. SELECT Id, MortgageID__c FROM Deal WHERE MortgageID__c IN :freshDataMap.keySet()
  28. ]);
  29.  
  30. // Handle existing deals and check for absent deals using a separate method
  31. Map<Id,Deal> absentData = Deal_Processing.getDealInstances(dealMap.keySet());
  32.  
  33. List<Deal> newEntries = new List<Deal>();
  34.  
  35. // Map the absent deals to be inserted
  36. for (Deal loanDeal : absentData.values()) {
  37. Deal adjustedDeal = Deal_Processing.applyMapping(loanDeal);
  38. if (adjustedDeal != null) { // Null check for safe processing.
  39. newEntries.add(adjustedDeal);
  40. }
  41. }
  42.  
  43. // Insert all new entries in bulk if there are any
  44. if (!newEntries.isEmpty()) {
  45. try {
  46. insert newEntries;
  47. } catch (DmlException ex) {
  48. // Log the error and handle failed inserts appropriately
  49. System.debug('Failed to insert deals: ' + ex.getMessage());
  50. }
  51. }
  52. }
  53. }
  54.  
Success #stdin #stdout #stderr 0.01s 10576KB
stdin
Standard input is empty
stdout
Object: UndefinedObject error: did not understand #StageProcessingHandler
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject class(Object)>>doesNotUnderstand: #StageProcessingHandler (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)
Object: nil error: did not understand #associationAt:ifAbsent:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt:ifAbsent: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:115)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:44)
stderr
./prog:2: parse error, expected '}'
./prog:13: expected expression
./prog:15: expected expression
./prog:38: expected expression
./prog:44: expected expression