From 729ec82f5e1e4b81547663dabb4927b539fa2caa Mon Sep 17 00:00:00 2001 From: Stewart Anderson Date: Wed, 2 Oct 2024 21:57:07 +0100 Subject: [PATCH] Fixes to Location Flows and Automation --- .../classes/ASCS_MovementTriggerHandler.cls | 99 ++ .../ASCS_MovementTriggerHandler.cls-meta.xml | 5 + .../ASCS_MovementTriggerHandlerTest.cls | 109 ++ ...CS_MovementTriggerHandlerTest.cls-meta.xml | 5 + .../default/classes/MovementTrigger.trigger | 12 + .../classes/MovementTrigger.trigger-meta.xml | 5 + .../Animal_Movement_Process.flow-meta.xml | 91 +- .../Animal_Movement_SubFlow.flow-meta.xml | 42 +- .../Location_Change_Status_Flow.flow-meta.xml | 982 ++---------------- ...n_Change_Unit_Status_SubFlow.flow-meta.xml | 41 +- force-app/main/default/lwc/jsconfig.json | 8 +- manifest/package.xml | 9 + 12 files changed, 423 insertions(+), 985 deletions(-) create mode 100644 force-app/main/default/classes/ASCS_MovementTriggerHandler.cls create mode 100644 force-app/main/default/classes/ASCS_MovementTriggerHandler.cls-meta.xml create mode 100644 force-app/main/default/classes/ASCS_MovementTriggerHandlerTest.cls create mode 100644 force-app/main/default/classes/ASCS_MovementTriggerHandlerTest.cls-meta.xml create mode 100644 force-app/main/default/classes/MovementTrigger.trigger create mode 100644 force-app/main/default/classes/MovementTrigger.trigger-meta.xml diff --git a/force-app/main/default/classes/ASCS_MovementTriggerHandler.cls b/force-app/main/default/classes/ASCS_MovementTriggerHandler.cls new file mode 100644 index 00000000..b25cbc74 --- /dev/null +++ b/force-app/main/default/classes/ASCS_MovementTriggerHandler.cls @@ -0,0 +1,99 @@ +public with sharing class ASCS_MovementTriggerHandler { + // Method to handle logic after insert + + public static void handleInsert(Map newMap) { + + // Check if the allocation toggle is set: + // Return out if allocation enabled is false + // ASCS_Allocation_Toggle__c toggle = ASCS_Allocation_Toggle__c.getOrgDefaults(); + // Boolean toggleValue = Boolean.valueOf(toggle.get('ASCS_Allocation_Enabled__c')); + // if(toggleValue == false) return; + + // Create a list(Incase more than one movement is created) of Location Ids to pass through to updateMovementCount function + List locationList = new List(); + + // Loop incase of bulk upload + for (animalshelters__Movement__c movement : newMap.values()) { + // Make sure the new movement value is current + if(movement.animalshelters__Current__c == true && movement.animalshelters__Location__c != null){ + // Add to Location List, for proccessing + locationList.add(movement.animalshelters__Location__c); + } + } + updateMovementCount(locationList); + } + + // Method to handle logic after update + public static void handleUpdate(Map newMap, Map oldMap) { + + // Return out if allocation enables is false + // ASCS_Allocation_Toggle__c toggle = ASCS_Allocation_Toggle__c.getOrgDefaults(); + // Boolean toggleValue = Boolean.valueOf(toggle.get('ASCS_Allocation_Enabled__c')); + // System.debug('Toggle' + toggleValue); + // if(toggleValue == false) return; + + // Create List of Locations + //Create Lost of Location Id Strings + List locationIdStringList = new List(); + + // Loop incase of bulk movement creation + for (Id movementId : newMap.keySet()) { + animalshelters__Movement__c newMovement = newMap.get(movementId); + animalshelters__Movement__c oldMovement = oldMap.get(movementId); + // Pull current value from new and onld map + Boolean oldCurrentValue = Boolean.valueOf(oldMovement.get('animalshelters__Current__c')); + Boolean newCurrentValue = Boolean.valueOf(newMovement.get('animalshelters__Current__c')); + + // Check that the movement current value has been changed + if(oldCurrentValue != newCurrentValue){ + // Add to location string list + String newLocation = String.valueOf(newMovement.get('animalshelters__Location__c')); + if(newLocation != null){ + locationIdStringList.add(newLocation); + } + } + } + updateMovementCount(locationIdStringList); + } + + // Method to pass in locationId List that updates the allocation based on movement count + public static void updateMovementCount(List locationIdStringList) { + Map movementCount = new Map(); + List locationList = new List(); + + // Perform the aggregate query to get count of movements per location + List results = [ + SELECT animalshelters__Location__c, COUNT(Id) + FROM animalshelters__Movement__c + WHERE animalshelters__Location__c IN :locationIdStringList AND animalshelters__Current__c = true + GROUP BY animalshelters__Location__c + ]; + + // Loop through the results and populate the map + for (AggregateResult result : results) { + String locationId = (String)result.get('animalshelters__Location__c'); + Integer count = (Integer)result.get('expr0'); + + // Create temp location to update the allocation + animalshelters__Locations__c tempLocation = new animalshelters__Locations__c(); + tempLocation.Id = locationId; + tempLocation.animalshelters__Allocation__c = count; + locationList.add(tempLocation); + // Add to map + movementCount.put(locationId, count); + } + + // Now handle locations that were not found in the query results + for (String locationId : locationIdStringList) { + // If the locationId is not present in the results, add it with an allocation of 0 + if (!movementCount.containsKey(locationId)) { + // Create a temp location with allocation 0 + animalshelters__Locations__c tempLocation = new animalshelters__Locations__c(); + tempLocation.Id = locationId; + tempLocation.animalshelters__Allocation__c = 0; + locationList.add(tempLocation); + } + } + update locationList; + } +} \ No newline at end of file diff --git a/force-app/main/default/classes/ASCS_MovementTriggerHandler.cls-meta.xml b/force-app/main/default/classes/ASCS_MovementTriggerHandler.cls-meta.xml new file mode 100644 index 00000000..651b1729 --- /dev/null +++ b/force-app/main/default/classes/ASCS_MovementTriggerHandler.cls-meta.xml @@ -0,0 +1,5 @@ + + + 61.0 + Active + diff --git a/force-app/main/default/classes/ASCS_MovementTriggerHandlerTest.cls b/force-app/main/default/classes/ASCS_MovementTriggerHandlerTest.cls new file mode 100644 index 00000000..d788471b --- /dev/null +++ b/force-app/main/default/classes/ASCS_MovementTriggerHandlerTest.cls @@ -0,0 +1,109 @@ +@isTest +private class ASCS_MovementTriggerHandlerTest { + + @TestSetup + static void setupTestData() { + // Fetch all necessary record type Ids in one go + Map recordTypeMap = Schema.SObjectType.animalshelters__Locations__c.getRecordTypeInfosByDeveloperName(); + String unitRecordTypeId = recordTypeMap.get('Unit').getRecordTypeId(); + String blockRecordTypeId = recordTypeMap.get('Block').getRecordTypeId(); + String siteRecordTypeId = recordTypeMap.get('Site').getRecordTypeId(); + + // Create the Site and Block locations + animalshelters__Locations__c locationSite = new animalshelters__Locations__c( + animalshelters__Name__c = 'Test Location Site', + recordTypeId = siteRecordTypeId + ); + + insert locationSite; + + animalshelters__Locations__c locationBlock = new animalshelters__Locations__c( + animalshelters__Name__c = 'Test Location Block', + recordTypeId = blockRecordTypeId, + animalshelters__Parent_Block__c = locationSite.Id + ); + + insert locationBlock ; + + // Create two Unit locations + List locationList = new List(); + animalshelters__Locations__c location1 = new animalshelters__Locations__c( + animalshelters__Name__c = 'Test Location', + recordTypeId = unitRecordTypeId, + animalshelters__Capacity__c = 5, + animalshelters__Parent_Block__c = locationBlock.Id + ); + + animalshelters__Locations__c location2 = new animalshelters__Locations__c( + animalshelters__Name__c = 'Test Location 2', + recordTypeId = unitRecordTypeId, + animalshelters__Capacity__c = 5, + animalshelters__Parent_Block__c = locationBlock.Id + ); + + locationList.add(location1); + locationList.add(location2); + + // Insert unit locations + insert locationList; + + // Create an Animal record + animalshelters__Animal__c animal = new animalshelters__Animal__c( + animalshelters__Microchip__c = '123456', + animalshelters__Animal_Name__c = 'Test Dog', + //ASCS_Status_Reason__c = 'None', + animalshelters__Date_of_Arrival__c = DateTime.now() + ); + insert animal; + } + + @IsTest + public static void testMovementTrigger() { + // Retrieve test data created in @TestSetup + animalshelters__Locations__c location1 = [SELECT Id, animalshelters__Allocation__c FROM animalshelters__Locations__c WHERE animalshelters__Name__c = 'Test Location' LIMIT 1]; + animalshelters__Locations__c location2 = [SELECT Id, animalshelters__Allocation__c FROM animalshelters__Locations__c WHERE animalshelters__Name__c = 'Test Location 2' LIMIT 1]; + animalshelters__Animal__c animal = [SELECT Id FROM animalshelters__Animal__c WHERE animalshelters__Animal_Name__c = 'Test Dog' LIMIT 1]; + + // Start test block for DML operation simulation + Test.startTest(); + + // Create the first Movement + animalshelters__Movement__c movement1 = new animalshelters__Movement__c( + animalshelters__Location__c = location1.Id, + animalshelters__Current__c = true, + animalshelters__Animal__c = animal.Id + ); + insert movement1; + + // Verify the first location's allocation after first movement + animalshelters__Locations__c updatedLocation1 = [SELECT animalshelters__Allocation__c FROM animalshelters__Locations__c WHERE Id = :location1.Id]; + System.assertEquals(1, updatedLocation1.animalshelters__Allocation__c); + + // Create the second movement, mark the first as inactive + animalshelters__Movement__c movement2 = new animalshelters__Movement__c( + animalshelters__Location__c = location2.Id, + animalshelters__Current__c = true, + animalshelters__Animal__c = animal.Id + ); + movement1.animalshelters__Current__c = false; + + // Insert new movement and update the first + insert movement2; + update movement1; + + // End test block + Test.stopTest(); + + // Query both locations for allocation check + List updatedLocations = [SELECT Id, animalshelters__Allocation__c FROM animalshelters__Locations__c WHERE Id IN :new Set{location1.Id, location2.Id}]; + + // Verify allocations after the movements + for (animalshelters__Locations__c loc : updatedLocations) { + if (loc.Id == location1.Id) { + System.assertEquals(0, loc.animalshelters__Allocation__c, 'Location 1 should have 0 allocation'); + } else if (loc.Id == location2.Id) { + System.assertEquals(1, loc.animalshelters__Allocation__c, 'Location 2 should have 1 allocation'); + } + } + } +} diff --git a/force-app/main/default/classes/ASCS_MovementTriggerHandlerTest.cls-meta.xml b/force-app/main/default/classes/ASCS_MovementTriggerHandlerTest.cls-meta.xml new file mode 100644 index 00000000..7d5f9e8a --- /dev/null +++ b/force-app/main/default/classes/ASCS_MovementTriggerHandlerTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 61.0 + Active + \ No newline at end of file diff --git a/force-app/main/default/classes/MovementTrigger.trigger b/force-app/main/default/classes/MovementTrigger.trigger new file mode 100644 index 00000000..b37fba05 --- /dev/null +++ b/force-app/main/default/classes/MovementTrigger.trigger @@ -0,0 +1,12 @@ +trigger MovementTrigger on animalshelters__Movement__c (after insert, after update) { + + // Called upon Create of new movement + if (Trigger.isInsert) { + ASCS_MovementTriggerHandler.handleInsert(Trigger.newMap); + } + + // Update an existing movement + if (Trigger.isUpdate) { + ASCS_MovementTriggerHandler.handleUpdate(Trigger.newMap, Trigger.oldMap); + } +} diff --git a/force-app/main/default/classes/MovementTrigger.trigger-meta.xml b/force-app/main/default/classes/MovementTrigger.trigger-meta.xml new file mode 100644 index 00000000..04b377d0 --- /dev/null +++ b/force-app/main/default/classes/MovementTrigger.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 61.0 + Active + diff --git a/force-app/main/default/flows/Animal_Movement_Process.flow-meta.xml b/force-app/main/default/flows/Animal_Movement_Process.flow-meta.xml index cf792641..7496c7de 100644 --- a/force-app/main/default/flows/Animal_Movement_Process.flow-meta.xml +++ b/force-app/main/default/flows/Animal_Movement_Process.flow-meta.xml @@ -396,10 +396,10 @@ BoarderLocations String - Block_Unit__c + animalshelters__Block_Unit__c and - Available_for_Boarding__c + animalshelters__Available_for_Boarding__c EqualTo true @@ -413,24 +413,24 @@ - Availability__c + animalshelters__Availability__c GreaterThan 0.0 - Locations__c + animalshelters__Locations__c LocationId Id - Block_Unit__c + animalshelters__Block_Unit__c Asc FosterLocations String - Name__c + animalshelters__Name__c and RecordTypeId @@ -440,24 +440,24 @@ - Availability__c + animalshelters__Availability__c GreaterThan 0.0 - Locations__c + animalshelters__Locations__c LocationId Id - Name__c + animalshelters__Name__c Asc OrganisationLocations String - Name__c + animalshelters__Name__c and RecordTypeId @@ -467,24 +467,24 @@ - Availability__c + animalshelters__Availability__c GreaterThan 0.0 - Locations__c + animalshelters__Locations__c LocationId Id - Name__c + animalshelters__Name__c Asc UnitLocations String - Block_Unit__c + animalshelters__Block_Unit__c and RecordTypeId @@ -494,25 +494,25 @@ - Availability__c + animalshelters__Availability__c GreaterThan 0.0 - Locations__c + animalshelters__Locations__c LocationId Id - Block_Unit__c + animalshelters__Block_Unit__c Asc Default DecrementAllocationBy1 Number - {!Get_Current_Location_Record.Allocation__c} - 1 + {!Get_Current_Location_Record.animalshelters__Allocation__c} - 1 0 Animal - Movement Process @@ -568,20 +568,20 @@ and - Animal__c + animalshelters__Animal__c EqualTo recordId.Id - Current__c + animalshelters__Current__c EqualTo true - Movement__c + animalshelters__Movement__c MovementRecords Id @@ -599,11 +599,11 @@ Id EqualTo - Get_Current_Movement_Record.Location__r.Id + Get_Current_Movement_Record.animalshelters__Location__r.Id true - Locations__c + animalshelters__Locations__c true @@ -621,21 +621,21 @@ and - Animal__c + animalshelters__Animal__c EqualTo recordId.Id - Current__c + animalshelters__Current__c EqualTo true true - Movement__c + animalshelters__Movement__c true @@ -660,18 +660,18 @@ - Current__c + animalshelters__Current__c false - End_Date__c + animalshelters__End_Date__c $Flow.CurrentDate - Movement__c + animalshelters__Movement__c Reset_Location_Status @@ -689,22 +689,22 @@ Id EqualTo - Get_Current_Movement_Record.Location__r.Id + Get_Current_Movement_Record.animalshelters__Location__r.Id - Allocation__c + animalshelters__Allocation__c DecrementAllocationBy1 - Unit_Status__c + animalshelters__Unit_Status__c Available - Locations__c + animalshelters__Locations__c Animal_Has_Existing_Location_Screen @@ -725,7 +725,7 @@ Region Animal_Has_Existing_Location_Screen_Text - <p><strong>{!recordId.Animal_Name__c}</strong> already has a current location</p><p><br></p><p><strong>{!Get_Current_Movement_Record.Location_Name__c}</strong></p><p><br></p><p><span style="color: rgb(68, 68, 68); background-color: rgb(255, 255, 255);">To leave the animal in its current location, exit here, or continue to assign a new location</span></p> + <p><strong>{!recordId.animalshelters__Animal_Name__c}</strong> already has a current location</p><p><br></p><p><strong>{!Get_Current_Movement_Record.animalshelters__Location_Name__c}</strong></p><p><br></p><p><span style="color: rgb(68, 68, 68); background-color: rgb(255, 255, 255);">To leave the animal in its current location, exit here, or continue to assign a new location</span></p> DisplayText @@ -746,7 +746,6 @@ String Do you wish to continue? RadioButtons - UseStoredValues false @@ -785,7 +784,6 @@ String Boarder Selection DropdownBox - UseStoredValues true true @@ -845,7 +843,6 @@ String Foster Selection DropdownBox - UseStoredValues true true @@ -883,7 +880,6 @@ String Choose a Movement DropdownBox - UseStoredValues true @@ -910,7 +906,6 @@ Movement Date InputField - UseStoredValues false @@ -942,7 +937,7 @@ false Movement_Complete_Screen_Text - <p><strong>Records Updated!</strong></p><p><br></p><p>The location for {!recordId.Animal_Name__c} has now been updated.</p><p><br></p><p>Please click Finish.</p> + <p><strong>Records Updated!</strong></p><p><br></p><p>The location for {!recordId.animalshelters__Animal_Name__c} has now been updated.</p><p><br></p><p>Please click Finish.</p> DisplayText true @@ -970,7 +965,6 @@ String Organisation Selection DropdownBox - UseStoredValues true true @@ -998,7 +992,6 @@ String Unit Selection DropdownBox - UseStoredValues true true @@ -1020,7 +1013,7 @@ Movement_Complete - Animal_Movement_SubFlow + animalshelters__Animal_Movement_SubFlow AnimalId @@ -1055,7 +1048,7 @@ Foster_Selection_Screen - Animal_RecordType_Subflow + animalshelters__Animal_RecordType_Subflow developerName @@ -1081,7 +1074,7 @@ Organisation_Selection_Screen - Animal_RecordType_Subflow + animalshelters__Animal_RecordType_Subflow developerName @@ -1107,7 +1100,7 @@ Initial_Screen - Animal_RecordType_Subflow + animalshelters__Animal_RecordType_Subflow developerName @@ -1153,7 +1146,7 @@ true false false - Movement__c + animalshelters__Movement__c newMovementType @@ -1168,7 +1161,7 @@ false true false - Animal__c + animalshelters__Animal__c recordTypeId @@ -1183,6 +1176,6 @@ false false false - Movement__c + animalshelters__Movement__c diff --git a/force-app/main/default/flows/Animal_Movement_SubFlow.flow-meta.xml b/force-app/main/default/flows/Animal_Movement_SubFlow.flow-meta.xml index 39dbe02b..964df658 100644 --- a/force-app/main/default/flows/Animal_Movement_SubFlow.flow-meta.xml +++ b/force-app/main/default/flows/Animal_Movement_SubFlow.flow-meta.xml @@ -36,14 +36,14 @@ 50 350 - varNewMovementRecord.Current__c + varNewMovementRecord.animalshelters__Current__c Assign false - varNewMovementRecord.Movement_Status__c + varNewMovementRecord.animalshelters__Movement_Status__c Assign Pending @@ -66,28 +66,28 @@ 182 134 - varNewMovementRecord.Animal__c + varNewMovementRecord.animalshelters__Animal__c Assign AnimalId - varNewMovementRecord.Start_Date__c + varNewMovementRecord.animalshelters__Start_Date__c Assign movementStartDate - varNewMovementRecord.Type__c + varNewMovementRecord.animalshelters__Type__c Assign movementType - varNewMovementRecord.Location__c + varNewMovementRecord.animalshelters__Location__c Assign LocationId @@ -119,14 +119,14 @@ 314 350 - varNewMovementRecord.Current__c + varNewMovementRecord.animalshelters__Current__c Assign true - varNewMovementRecord.Movement_Status__c + varNewMovementRecord.animalshelters__Movement_Status__c Assign Completed @@ -221,15 +221,15 @@ fmlLocationName String IF( -{!movementType} = "Housed", -{!movementType} + " - " + {!Get_Newly_Created_Movement_Record.Location_Name__c}, +{!movementType} = "Housed", +{!movementType} + " - " + {!Get_Newly_Created_Movement_Record.animalshelters__Location_Name__c}, {!movementType} ) IncrementAllocationBy1 Number - {!Get_Location_Record.Allocation__c} + 1 + {!Get_Location_Record.animalshelters__Allocation__c} + 1 0 Animal - Movement SubFlow @@ -289,7 +289,7 @@ true - Locations__c + animalshelters__Locations__c true @@ -314,7 +314,7 @@ true - Movement__c + animalshelters__Movement__c true @@ -334,18 +334,18 @@ - Location_Status__c + animalshelters__Location_Status__c fmlLocationName - Site__c + animalshelters__Site__c - Get_Newly_Created_Movement_Record.Sitename__c + Get_Newly_Created_Movement_Record.animalshelters__Sitename__c - Animal__c + animalshelters__Animal__c Update_Location_Allocation @@ -364,12 +364,12 @@ - Allocation__c + animalshelters__Allocation__c IncrementAllocationBy1 - Locations__c + animalshelters__Locations__c 56 @@ -384,7 +384,7 @@ 50 1490 - Animal_Generate_Tasks_Subflow + animalshelters__Animal_Generate_Tasks_Subflow animalRecordId @@ -464,6 +464,6 @@ false false false - Movement__c + animalshelters__Movement__c diff --git a/force-app/main/default/flows/Location_Change_Status_Flow.flow-meta.xml b/force-app/main/default/flows/Location_Change_Status_Flow.flow-meta.xml index 602d146e..36f14464 100644 --- a/force-app/main/default/flows/Location_Change_Status_Flow.flow-meta.xml +++ b/force-app/main/default/flows/Location_Change_Status_Flow.flow-meta.xml @@ -1,141 +1,12 @@ 60.0 - - Add_SubBlock_to_Variable - - 2184 - 782 - - subBlocks - Add - - Get_SubBlock_for_Block_in_Site.childRecords - - - - Get_SubBlock_for_Each_Block - - - - Add_Sublocks - - 1656 - 1706 - - subBlocks - Add - - Get_SubBlock_for_Block.childRecords - - - - Set_Block_Record_Details - - - - Add_Unit_for_Each_Block_SubBlock - - 2184 - 1298 - - Units - Add - - Get_Units_for_Each_Block_in_Site.childRecords - - - - Loop_Through_All_Blocks_SubBlocks - - - - Add_Units - - 1788 - 998 - - Units - Add - - Get_Units_for_Each_SubBlock.childRecords - - - - Loop_Through_SubBlocks - - Assigns the output of Get Units Related to Block Subflow to the Units Collection Assign_Block_Units_to_Collection - 1348 - 782 - - Units - Add - - Get_Units_Related_to_Block.childRecords - - - - Change_Block_Units_Status_and_Check_for_Allocated_Units - - - - Build_Block_Updates - - 1744 - 2030 - - subBlock_Blocks - Add - - subBlock_Block - - - - Set_Block_Record_Details - - - - Build_Block_Updates_Site - - 2316 - 1922 - - subBlock_Blocks - Add - - subBlock_Block - - - - Loop_Through_all_Site_Blocks_SubBlocks - - - - Combine_All_Blocks_and_SubBlocks_for_Site - - 2096 - 974 - - subBlocks - Add - - Get_Blocks_Related_to_Site.childRecords - - - - Loop_Through_All_Blocks_SubBlocks - - - - Combine the SubBlock Units and Block Units - Combine_All_Units - - 1700 - 1190 + 380 + 566 Units Add @@ -144,173 +15,43 @@ - Change_Block_Units_Status_and_Check_for_Allocated_Units + ASCS_Change_Block_Units_Status_and_Check_for_Allocated_Units - Combine_Block_SubBlock_records - - 1656 - 1598 - - subBlocks - Add - - recordId - - - - Add_Sublocks - - - - Get_Selected_Choice - - 1084 + Reset_Unavailability_Reason + + 578 890 - SelectedChoice - Assign - - Status_Options - - - - Update_Block_Status - - - - Set_Block_details - - 1744 - 1922 - - subBlock_Block.Block_Status__c - Assign - - Status_Options - - - - subBlock_Block.Unavailability_Reason__c - Assign - - resetUnavailableReason - - - - subBlock_Block.Id + recordId.animalshelters__Unavailability_Reason__c Assign - - Set_Block_Record_Details.Id - - Build_Block_Updates - - - - Set_Block_details_Site - - 2316 - 1814 - - subBlock_Block.Block_Status__c - Assign - - Status_Options - - - - subBlock_Block.Unavailability_Reason__c - Assign - - resetUnavailableReason - - - - subBlock_Block.Id - Assign - - Loop_Through_all_Site_Blocks_SubBlocks.Id - - - - Build_Block_Updates_Site - - - - Set_Unit_as_Available - - 50 - 1166 - - Unit_Assignment.Id - Assign - - recordId.Id - - - - Unit_Assignment.Allocation__c - Assign - - formulaUnitAvailableAllocation - - - - Unit_Assignment.Unit_Status__c - Assign - - Available - - - - Unit_Assignment.Unavailability_Reason__c - Assign - - - - - - Update_Unit + Update_Block_Status_Block - Set_Unit_as_Unavailable - + Set_Unavailability_Details + 314 - 1166 - - Unit_Assignment.Id - Assign - - recordId.Id - - - - Unit_Assignment.Allocation__c - Assign - - formulaUnitUnavailableAllocation - - + 998 - Unit_Assignment.Unit_Status__c + recordId.animalshelters__Block_Status__c Assign Unavailable - Unit_Assignment.Unavailability_Reason__c + recordId.animalshelters__Unavailability_Reason__c Assign Reason_Unavailable - Update_Unit + Update_Block_Status_Block @@ -330,242 +71,71 @@ - Are_There_SubBlock_Units - - 820 - 566 - - Change_SubBlock_Units_Status_and_Check_for_Allocations - - SubBlock Units - - No_SubBlock_Units - and - - Get_SubBlock_Units.childRecords - IsNull - - true - - - - - - - Are_there_SubBlocks - - 1524 - 674 - - Loop_Through_SubBlocks - - Default Outcome - - No_SubBlocks - and - - Get_SubBlock_for_Block.childRecords - IsNull - - true - - - - Assign_Block_Units_to_Collection - - - - - - Did_Block_Have_Allocated_Units - - 1524 - 1490 - - Combine_Block_SubBlock_records - - No - Block hasn't - - Yes_Block_has - and - - allocatedUnits - EqualTo - - true - - - - Has_Allocated_Units - - - - - - Did_SubBlock_Have_Allocated_Units - - 996 + Copy_2_of_Location_Set_Unavailable + + 380 782 - Get_Selected_Choice - - No - SubBlock hasn't - - Yes_SubBlock_has - and - - allocatedUnits - EqualTo - - true - - - - Has_Allocated_Units - - - - - - Does_Unit_have_an_Allocation - - 336 - 566 - - Unit_Available_or_Unavailable - - No Allocations - - Yes_Unit_has_Allocations - and - - recordId.Allocation__c - GreaterThan - - 0.0 - - - - Unit_Has_Allocation - - - - - - Is_the_Ignore_Allocated_Units_Flag_Set - - 182 - 458 - - Does_Unit_have_an_Allocation - - No - Honour Allocations - - Yes_Ignore_Allocations - and - - Ignore_Allocated_Units - EqualTo - - true - - - - Unit_Available_or_Unavailable - - - - - - Has the Unit be set as Available or Unavailable? - Unit_Available_or_Unavailable - - 182 - 1058 - - Set_Unit_as_Unavailable + Reset_Unavailability_Reason Default Outcome - Available + Copy_2_of_Unavailable and Status_Options EqualTo - Available_Choice - - - - Set_Unit_as_Available - - - - - - Were_there_any_Allocated_Units - - 2096 - 1598 - - Loop_Through_all_Site_Blocks_SubBlocks - - No - Allocated Units - - Yes_Allocated_Units - and - - allocatedUnits - EqualTo - - true + Unavailable_Choice - Has_Allocated_Units + Did_Block_Have_Allocated_Units - + - What_is_the_Locations_RecordType - - 1337 - 350 + Did_Block_Have_Allocated_Units + + 182 + 890 - Location_RecordType_Error + Set_Unavailability_Details - Error + No - Block hasn't - Unit + Yes_Block_has and - recordId.RecordType.DeveloperName + allocatedUnits EqualTo - Unit + true - - Is_the_Ignore_Allocated_Units_Flag_Set - - - - - Sub_Block - and - recordId.RecordType.DeveloperName + Ignore_Allocated_Units EqualTo - SubBlock + false - Get_SubBlock_Units + Has_Allocated_Units - + + + + What_is_the_Locations_RecordType + + 611 + 350 + + Location_RecordType_Error + + Error Block and @@ -577,126 +147,39 @@ - Get_SubBlock_for_Block + Get_Units_Related_to_Block - - Site - and - - recordId.RecordType.Name - EqualTo - - Site - - - - Get_Blocks_Related_to_Site - - - - [Animal Shelter] - Flow to change the Status of a Unit, Sub Block or Block to make the associated Units Available or Unavailable Reason_Unavailable_Picklist Picklist - Unavailability_Reason__c - Locations__c + animalshelters__Unavailability_Reason__c + animalshelters__Locations__c Default formulaUnitAvailableAllocation Number - IF({!Ignore_Allocated_Units} = TRUE, {!recordId.Allocation__c}, 0) + IF({!Ignore_Allocated_Units} = TRUE, {!recordId.animalshelters__Allocation__c}, 0) 0 formulaUnitUnavailableAllocation Number - IF({!Ignore_Allocated_Units} = TRUE, {!recordId.Allocation__c}, {!recordId.Capacity__c}) + IF({!Ignore_Allocated_Units} = TRUE, {!recordId.animalshelters__Allocation__c}, {!recordId.animalshelters__Capacity__c}) 0 resetUnavailableReason String - IF({!Status_Options} = 'Available', ' ', {!Reason_Unavailable}) + IF( ISPICKVAL({!recordId.animalshelters__Unavailability_Reason__c}, 'Unavailable'), 'Available', TEXT({!recordId.animalshelters__Unavailability_Reason__c})) - Location - Change Status Flow {!$Flow.CurrentDateTime} - true - - - Get_SubBlock_for_Each_Block - - 2096 - 566 - Get_Blocks_Related_to_Site.childRecords - Asc - - Get_SubBlock_for_Block_in_Site - - - Combine_All_Blocks_and_SubBlocks_for_Site - - - - Loop_Through_All_Blocks_SubBlocks - - 2096 - 1082 - subBlocks - Asc - - Get_Units_for_Each_Block_in_Site - - - Change_Units_Status_for_All_Site_Units - - - - Loop_Through_all_Site_Blocks_SubBlocks - - 2228 - 1706 - subBlocks - Asc - - Set_Block_details_Site - - - Update_Block_Status_Site - - - - Loop_Through_SubBlocks - - 1700 - 782 - Get_SubBlock_for_Block.childRecords - Asc - - Get_Units_for_Each_SubBlock - - - Combine_All_Units - - - - Set_Block_Record_Details - - 1656 - 1814 - subBlocks - Asc - - Set_Block_details - - - Update_Block_Status_Block - - + ASCS Location - Change Status Flow {!$Flow.CurrentDateTime} + BuilderType @@ -716,76 +199,27 @@ Flow - - Update_Block_Status - - 1084 - 998 - - Completed - - and - - Id - EqualTo - - recordId.Id - - - - Block_Status__c - - Status_Options - - - - Unavailability_Reason__c - - resetUnavailableReason - - - Locations__c - Update_Block_Status_Block - 1656 - 2222 - - true - Completed - - subBlock_Blocks - - - Update_Block_Status_Site - - 2228 - 2114 + 380 + 1382 - true Completed - subBlock_Blocks - - - Update_Unit - - 182 - 1358 - Unit_Assignment + recordId Completed - 1084 - 1106 + 380 + 1490 false true false Completed_Text - <p><strong>Locations Updated!</strong></p><p><br></p><p>All units in {!recordId.Name__c} have been updated to {!SelectedChoice}. Click Finish to complete the wizard.</p> + <p><strong>Locations Updated!</strong></p><p><br></p><p>All units in {!recordId.animalshelters__Name__c} have been updated to {!Status_Options}. Click Finish to complete the wizard.</p> DisplayText true @@ -794,14 +228,14 @@ Has_Allocated_Units - 1337 - 2564 + 50 + 998 false true false Copy_1_of_Has_Allocated_Units_Text - <p>Block/Sub Block <strong><em>{!recordId.Name__c}</em></strong> has at least 1 unit that is housing an animal, and is allocated. </p><p><br></p><p>Please make arrangements to move the animals out of any units in this Block/Sub Block.</p><p><br></p><p>Click <strong>Finish</strong> to Exit</p> + <p>Block/Sub Block <strong><em>{!recordId.animalshelters__Name__c}</em></strong> has at least 1 unit that is housing an animal, and is allocated. </p><p><br></p><p>Please make arrangements to move the animals out of any units in this Block/Sub Block.</p><p><br></p><p>Click <strong>Finish</strong> to Exit</p> DisplayText true @@ -810,7 +244,7 @@ Initial_Screen - 1337 + 611 134 false true @@ -836,7 +270,6 @@ String Status Options RadioButtons - UseStoredValues false @@ -856,8 +289,7 @@ String Reason Unavailable DropdownBox - UseStoredValues - false + true and @@ -875,9 +307,8 @@ false - Ignore Allocated Units + Update Status Regardless of Unit Occupancy InputField - UseStoredValues true and @@ -923,37 +354,22 @@ Location_RecordType_Error - 2492 + 842 458 false true false Location_RecordType_Error_Text - <p>ERROR! - The Location {!recordId.Name__c} has no Record Type</p> - DisplayText - - true - true - - - Unit_Has_Allocation - - 204 - 674 - false - true - false - - Unit_Has_Allocation_Text - <p>Unit <strong><em>{!recordId.Name__c}</em></strong> has an allocation. </p><p><br></p><p>Please make arrangements to move the animal(s) out of the the unit.</p><p><br></p><p>Click <strong>Finish</strong> to Exit</p> + <p>ERROR! - The Location {!recordId.animalshelters__Name__c} must be a Block</p> DisplayText true true + animalshelters__Location_Change_Status_Flow - 1211 + 485 0 Initial_Screen @@ -961,88 +377,12 @@ Active - Change_Block_Units_Status_and_Check_for_Allocated_Units + ASCS_Change_Block_Units_Status_and_Check_for_Allocated_Units - 1524 - 1382 - - Did_Block_Have_Allocated_Units - - Location_Change_Unit_Status_SubFlow - - ignoreAllocatedUnits - - Ignore_Allocated_Units - - - - newStatus - - Status_Options - - - - newUnavailabilityReason - - Reason_Unavailable - - - - unitsForStatusChange - - Units - - - - allocatedUnits - unitsHaveAllocation - - - - Change_SubBlock_Units_Status_and_Check_for_Allocations - - 996 + 380 674 - Did_SubBlock_Have_Allocated_Units - - Location_Change_Unit_Status_SubFlow - - newStatus - - Status_Options - - - - newUnavailabilityReason - - Reason_Unavailable - - - - unitsForStatusChange - - Get_SubBlock_Units.childRecords - - - - ignoreAllocatedUnits - - Ignore_Allocated_Units - - - - allocatedUnits - unitsHaveAllocation - - - - Change_Units_Status_for_All_Site_Units - - 2096 - 1490 - - Were_there_any_Allocated_Units + Copy_2_of_Location_Set_Unavailable Location_Change_Unit_Status_SubFlow @@ -1074,38 +414,15 @@ unitsHaveAllocation - - Get_Blocks_Related_to_Site - - 2096 - 458 - - Get_SubBlock_for_Each_Block - - Location_Get_Location_Child_Records_Subflow - - childRecordTypeName - - Block - - - - locationRecord - - recordId - - - true - Get_RecordType_Id_for_Unit - 1337 + 611 242 What_is_the_Locations_RecordType - Animal_RecordType_Subflow + animalshelters__Animal_RecordType_Subflow developerName @@ -1120,130 +437,15 @@ true - - Get_SubBlock_for_Block - - 1524 - 458 - - Get_Units_Related_to_Block - - Location_Get_Location_Child_Records_Subflow - - childRecordTypeName - - SubBlock - - - - locationRecord - - recordId - - - true - - - Get_SubBlock_for_Block_in_Site - - 2184 - 674 - - Add_SubBlock_to_Variable - - Location_Get_Location_Child_Records_Subflow - - childRecordTypeName - - SubBlock - - - - locationRecord - - Get_SubBlock_for_Each_Block - - - true - - - Get_SubBlock_Units - - 820 - 458 - - Are_There_SubBlock_Units - - Location_Get_Location_Child_Records_Subflow - - childRecordTypeName - - Unit - - - - locationRecord - - recordId - - - true - - - Get_Units_for_Each_Block_in_Site - - 2184 - 1190 - - Add_Unit_for_Each_Block_SubBlock - - Location_Get_Location_Child_Records_Subflow - - childRecordTypeName - - Unit - - - - locationRecord - - Loop_Through_All_Blocks_SubBlocks - - - true - - - Get_Units_for_Each_SubBlock - - 1788 - 890 - - Add_Units - - Location_Get_Location_Child_Records_Subflow - - childRecordTypeName - - Unit - - - - locationRecord - - Loop_Through_SubBlocks - - - true - Get_Units_Related_to_Block - 1524 - 566 + 380 + 458 - Are_there_SubBlocks + Assign_Block_Units_to_Collection - Location_Get_Location_Child_Records_Subflow + animalshelters__Location_Get_Location_Child_Records_Subflow childRecordTypeName @@ -1271,7 +473,7 @@ false false false - Locations__c + animalshelters__Locations__c currentItem_Filter_for_MultiAnimal_Units @@ -1279,7 +481,7 @@ false false false - Locations__c + animalshelters__Locations__c currentItem_Filter_for_Units_with_an_Allocation @@ -1287,7 +489,7 @@ false false false - Locations__c + animalshelters__Locations__c currentItem_Filter_Units_for_Allocated_Units @@ -1295,7 +497,15 @@ false false false - Locations__c + animalshelters__Locations__c + + + localLocation + SObject + false + false + false + animalshelters__Locations__c recordId @@ -1303,7 +513,7 @@ false true false - Locations__c + animalshelters__Locations__c SelectedChoice @@ -1318,7 +528,7 @@ false false false - Locations__c + animalshelters__Locations__c subBlock_Blocks @@ -1326,7 +536,7 @@ true false false - Locations__c + animalshelters__Locations__c subBlocks @@ -1334,7 +544,7 @@ true false false - Locations__c + animalshelters__Locations__c Unit_Assignment @@ -1342,7 +552,7 @@ false false false - Locations__c + animalshelters__Locations__c Units @@ -1350,6 +560,6 @@ true false false - Locations__c + animalshelters__Locations__c diff --git a/force-app/main/default/flows/Location_Change_Unit_Status_SubFlow.flow-meta.xml b/force-app/main/default/flows/Location_Change_Unit_Status_SubFlow.flow-meta.xml index 2d7ba4ca..9108a747 100644 --- a/force-app/main/default/flows/Location_Change_Unit_Status_SubFlow.flow-meta.xml +++ b/force-app/main/default/flows/Location_Change_Unit_Status_SubFlow.flow-meta.xml @@ -51,13 +51,6 @@ 336 1166 - - updatedUnit.Allocation__c - Assign - - formulaAllocationAvailable - - updatedUnit.Id Assign @@ -66,14 +59,14 @@ - updatedUnit.Unavailability_Reason__c + updatedUnit.animalshelters__Unavailability_Reason__c Assign - updatedUnit.Unit_Status__c + updatedUnit.animalshelters__Unit_Status__c Assign newStatus @@ -88,13 +81,6 @@ 600 1166 - - updatedUnit.Allocation__c - Assign - - formulaAllocationUnavailable - - updatedUnit.Id Assign @@ -103,14 +89,14 @@ - updatedUnit.Unavailability_Reason__c + updatedUnit.animalshelters__Unavailability_Reason__c Assign newUnavailabilityReason - updatedUnit.Unit_Status__c + updatedUnit.animalshelters__Unit_Status__c Assign Unavailable @@ -163,14 +149,14 @@ unitsForStatusChange and - currentItem_Filter_Units_for_Allocated_Units.Allocation__c + currentItem_Filter_Units_for_Allocated_Units.animalshelters__Allocation__c GreaterThan 0.0 - currentItem_Filter_Units_for_Allocated_Units.Unit_Status__c + currentItem_Filter_Units_for_Allocated_Units.animalshelters__Unit_Status__c EqualTo Allocated @@ -255,22 +241,20 @@ - [Animal Shelter] - Subflow to change the status of units. Inputs: Unit record collection, Ignore Allocated Units Flag, Outputs: Allocated Units Default formulaAllocationAvailable Number - IF({!ignoreAllocatedUnits} = TRUE, {!Loop_Through_All_Units.Allocation__c}, 0) + IF({!ignoreAllocatedUnits} = TRUE, {!Loop_Through_All_Units.animalshelters__Allocation__c}, 0) 0 formulaAllocationUnavailable Number - IF({!ignoreAllocatedUnits} = TRUE, {!Loop_Through_All_Units.Allocation__c}, {!Loop_Through_All_Units.Capacity__c}) + IF({!ignoreAllocatedUnits} = TRUE, {!Loop_Through_All_Units.animalshelters__Allocation__c}, {!Loop_Through_All_Units.animalshelters__Capacity__c}) 0 Location - Change Unit Status SubFlow {!$Flow.CurrentDateTime} - true Loop_Through_All_Units @@ -312,6 +296,7 @@ 1550 updatedUnits + animalshelters__Location_Change_Unit_Status_SubFlow 122 0 @@ -334,7 +319,7 @@ false false false - Locations__c + animalshelters__Locations__c If True allocated units will be ignored and the status will still be set @@ -364,7 +349,7 @@ true true false - Locations__c + animalshelters__Locations__c unitsHaveAllocation @@ -379,7 +364,7 @@ false false false - Locations__c + animalshelters__Locations__c updatedUnits @@ -387,6 +372,6 @@ true false false - Locations__c + animalshelters__Locations__c diff --git a/force-app/main/default/lwc/jsconfig.json b/force-app/main/default/lwc/jsconfig.json index c613acd4..33cf8565 100644 --- a/force-app/main/default/lwc/jsconfig.json +++ b/force-app/main/default/lwc/jsconfig.json @@ -1,6 +1,12 @@ { "compilerOptions": { - "experimentalDecorators": true + "experimentalDecorators": true, + "baseUrl": ".", + "paths": { + "c/*": [ + "*" + ] + } }, "include": [ "**/*", diff --git a/manifest/package.xml b/manifest/package.xml index e3953b5e..fe008b9e 100644 --- a/manifest/package.xml +++ b/manifest/package.xml @@ -24,6 +24,8 @@ W3WInvocableCalloutTest What3Words What3WordsTest + ASCS_MovementTriggerHandler + ASCS_MovementTriggerHandlerTest ApexClass @@ -555,6 +557,8 @@ Movement_Object_Handler Task_Close_associated_Animal_Action Task_Update_Future_Movement_Record_on_Task_Completion + Location_Change_Status_Flow + Location_Change_Unit_Status_SubFlow Flow @@ -604,6 +608,7 @@ microchipLookup recordAlerts recordImage + lightningLocationMap LightningComponentBundle @@ -762,5 +767,9 @@ Movement__c Workflow + + MovementTrigger + ApexTrigger + 58.0