I have written this handler class which is called from the trigger. This code is not updating any on the below field when the trigger is executed. Can anyone please help me debug why my field update is not working?
// Set the "SCMC__Condition_Code__c" field to null
inspection.SCMC__Condition_Code__c = null;
// Set the "SCMC__Quantity_to_Accept__c" field to the "SCMC__Received_Quantity__c" field
inspection.SCMC__Quantity_to_Accept__c = inspection.SCMC__Received_Quantity__c;
public class diab_SetQuantityAndCallAPI {
public static List<SCMC__Receiving_Inspection__c> handleAfterInsert(Map<Id,SCMC__Receiving_Inspection__c> newInspectionsmap) {
// Create a list of inspections to pass to the API
List<SCMC__Receiving_Inspection__c> inspections = new List<SCMC__Receiving_Inspection__c>();
List<SCMC__Receiving_Inspection__c> newinspections = [SELECT Id, Name, SCMC__Inspection_Type__c,SCMC__Condition_Code__c,
SCMC__Quantity_to_Accept__c,SCMC__Total_Quantity_Accepted__c,SCMC__Received_Quantity__c
FROM SCMC__Receiving_Inspection__c where ID IN:newinspectionsmap.keySet() ];
// Iterate over the new records
for (SCMC__Receiving_Inspection__c inspection : newInspections) {
// Only perform the update and API call if the inspection type is "Customer_Return"
if (inspection.SCMC__Inspection_Type__c == 'Customer_Return') {
// Set the "SCMC__Condition_Code__c" field to null
inspection.SCMC__Condition_Code__c = null;
system.debug('Inside For Loop');
// Set the "SCMC__Quantity_to_Accept__c" field to the "SCMC__Received_Quantity__c" field
inspection.SCMC__Quantity_to_Accept__c = inspection.SCMC__Received_Quantity__c;
//inspection.SCMC__Total_Quantity_Accepted__c = inspection.SCMC__Received_Quantity__c;
// Add the inspection to the list to pass to the API
inspections.add(inspection);
}
}
system.debug('Inspection values--->' + inspections);
// Call the API with the list of inspections and the parameter "123"
/* if (!inspections.isEmpty()) {
SCMC.InventoryAPI api = new SCMC.InventoryAPI();
api.inspect(inspections, '123');
} */
return inspections;
}
}
Below is the trigger
trigger diab_SetQuantityAndCallInventoryAPI on SCMC__Receiving_Inspection__c (before update,after update) {
List<SCMC__Receiving_Inspection__c> ReceivedInspections = diab_SetQuantityAndCallAPI.handleAfterInsert(Trigger.newmap);
if (!ReceivedInspections.isEmpty()) {
SCMC.InventoryAPI api = new SCMC.InventoryAPI();
// api.inspect(ReceivedInspections, '123');
}
}