Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekStewie committed Nov 6, 2024
1 parent 42277ab commit 451f9dc
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 109 deletions.
16 changes: 8 additions & 8 deletions force-app/main/default/classes/ASCS_MovementTriggerHandler.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ public with sharing class ASCS_MovementTriggerHandler {
// Method to handle logic after insert

public static void handleInsert(Map<Id, animalshelters__Movement__c> 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();
Expand All @@ -25,25 +25,25 @@ public with sharing class ASCS_MovementTriggerHandler {

// Method to handle logic after update
public static void handleUpdate(Map<Id, animalshelters__Movement__c> newMap, Map<Id, animalshelters__Movement__c> 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 List of Locations
//Create Lost of Location Id Strings
List<String> locationIdStringList = new List<String>();

// 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
Expand All @@ -68,12 +68,12 @@ public with sharing class ASCS_MovementTriggerHandler {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private class ASCS_MovementTriggerHandlerTest {
);

insert locationSite;

animalshelters__Locations__c locationBlock = new animalshelters__Locations__c(
animalshelters__Name__c = 'Test Location Block',
recordTypeId = blockRecordTypeId,
Expand All @@ -43,7 +43,7 @@ private class ASCS_MovementTriggerHandlerTest {

locationList.add(location1);
locationList.add(location2);

// Insert unit locations
insert locationList;

Expand Down Expand Up @@ -96,7 +96,7 @@ private class ASCS_MovementTriggerHandlerTest {

// Query both locations for allocation check
List<animalshelters__Locations__c> updatedLocations = [SELECT Id, animalshelters__Allocation__c FROM animalshelters__Locations__c WHERE Id IN :new Set<Id>{location1.Id, location2.Id}];

// Verify allocations after the movements
for (animalshelters__Locations__c loc : updatedLocations) {
if (loc.Id == location1.Id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<description>[Animal Shelter] - When Adoption Status = Adopted: Update Contact Flag, Clear current and create new Movement record, update Animal status and details</description>
<description>[Animal Shelter] - When Adoption Status = Adopted: Update Contact Flag, Clear
current and create new Movement record, update Animal status and details</description>
<environments>Default</environments>
<formulas>
<name>formulaAdoptionDate</name>
<dataType>Date</dataType>
<expression>IF(ISBLANK({!$Record.animalshelters__Date_of_Adoption__c}) , {!$Flow.CurrentDate}, {!$Record.animalshelters__Date_of_Adoption__c})</expression>
<expression>IF(ISBLANK({!$Record.animalshelters__Date_of_Adoption__c}) ,
{!$Flow.CurrentDate}, {!$Record.animalshelters__Date_of_Adoption__c})</expression>
</formulas>
<formulas>
<name>formulaCollectedDate</name>
<dataType>Date</dataType>
<expression>IF(ISBLANK({!$Record.animalshelters__Date_Collected__c}) , {!$Flow.CurrentDate}, {!$Record.animalshelters__Date_Collected__c})</expression>
<expression>IF(ISBLANK({!$Record.animalshelters__Date_Collected__c}) , {!$Flow.CurrentDate},
{!$Record.animalshelters__Date_Collected__c})</expression>
</formulas>
<interviewLabel>Animal - Adoption Update Automation</interviewLabel>
<isTemplate>true</isTemplate>
Expand All @@ -36,7 +39,8 @@
</processMetadataValues>
<processType>AutoLaunchedFlow</processType>
<recordCreates>
<description>Creates a new Movement Record, of Type Adopted with the Start Date = to Date Collected</description>
<description>Creates a new Movement Record, of Type Adopted with the Start Date = to Date
Collected</description>
<name>Create_New_Movement_Record</name>
<label>Create New Movement Record</label>
<locationX>176</locationX>
Expand Down Expand Up @@ -129,7 +133,7 @@
<stringValue>Available</stringValue>
</value>
</inputAssignments>
<object>Locations__c</object>
<object>animalshelters__Locations__c</object>
</recordUpdates>
<recordUpdates>
<description>Close Outstanding Animal Action Records</description>
Expand Down Expand Up @@ -220,7 +224,8 @@
<object>Movement__c</object>
</recordUpdates>
<recordUpdates>
<description>Sets the &quot;Is An Adopter&quot; Flag on the associated Contact to indicate they are an Adopter</description>
<description>Sets the &quot;Is An Adopter&quot; Flag on the associated Contact to indicate
they are an Adopter</description>
<name>Set_Adopter_Flag_on_Contact_to_True</name>
<label>Set Adopter Flag on Contact to True</label>
<locationX>176</locationX>
Expand Down Expand Up @@ -321,4 +326,4 @@
<triggerType>RecordAfterSave</triggerType>
</start>
<status>Active</status>
</Flow>
</Flow>
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
<stringValue>Available</stringValue>
</value>
</filters>
<object>Locations__c</object>
<object>animalshelters__Locations__c</object>
<outputReference>varLocationChildRecords</outputReference>
<queriedFields>Id</queriedFields>
</recordLookups>
Expand All @@ -166,7 +166,7 @@
<elementReference>varLocationId</elementReference>
</value>
</filters>
<object>Locations__c</object>
<object>animalshelters__Locations__c</object>
<outputReference>varLocationChildRecords</outputReference>
<queriedFields>Id</queriedFields>
</recordLookups>
Expand All @@ -189,7 +189,7 @@
<elementReference>conZero</elementReference>
</value>
</inputAssignments>
<object>Locations__c</object>
<object>animalshelters__Locations__c</object>
</recordUpdates>
<recordUpdates>
<description>Update the Available Capacity value on the current Location</description>
Expand All @@ -211,7 +211,7 @@
<elementReference>varAvailableCount</elementReference>
</value>
</inputAssignments>
<object>Locations__c</object>
<object>animalshelters__Locations__c</object>
</recordUpdates>
<recordUpdates>
<description>Update the Total Capacity value on the current Location</description>
Expand All @@ -236,7 +236,7 @@
<elementReference>varTotalCount</elementReference>
</value>
</inputAssignments>
<object>Locations__c</object>
<object>animalshelters__Locations__c</object>
</recordUpdates>
<start>
<locationX>100</locationX>
Expand All @@ -260,15 +260,15 @@
<isCollection>false</isCollection>
<isInput>false</isInput>
<isOutput>false</isOutput>
<objectType>Locations__c</objectType>
<objectType>animalshelters__Locations__c</objectType>
</variables>
<variables>
<name>varLocationChildRecords</name>
<dataType>SObject</dataType>
<isCollection>true</isCollection>
<isInput>false</isInput>
<isOutput>false</isOutput>
<objectType>Locations__c</objectType>
<objectType>animalshelters__Locations__c</objectType>
</variables>
<variables>
<name>varLocationId</name>
Expand All @@ -285,4 +285,4 @@
<isOutput>false</isOutput>
<scale>0</scale>
</variables>
</Flow>
</Flow>
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
<elementReference>Get_Unit_RecordType_Id.returnedRecordTypeId</elementReference>
</value>
</filters>
<object>Locations__c</object>
<object>animalshelters__Locations__c</object>
<outputReference>AllRecords</outputReference>
<queriedFields>Id</queriedFields>
<queriedFields>Allocation__c</queriedFields>
Expand Down Expand Up @@ -333,7 +333,7 @@
<elementReference>SelectedChoice</elementReference>
</value>
</inputAssignments>
<object>Locations__c</object>
<object>animalshelters__Locations__c</object>
</recordUpdates>
<recordUpdates>
<name>Update_Unit_Status_to_Available</name>
Expand Down Expand Up @@ -368,7 +368,7 @@
<numberValue>0.0</numberValue>
</value>
</inputAssignments>
<object>Locations__c</object>
<object>animalshelters__Locations__c</object>
</recordUpdates>
<recordUpdates>
<name>Update_Unit_Status_to_Unavailable</name>
Expand All @@ -393,7 +393,10 @@
<allowPause>false</allowPause>
<fields>
<name>Completed_Text</name>
<fieldText>&lt;p&gt;&lt;strong&gt;Records Updated!&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;All units in {!recordId.Name__c} have been updated to {!SelectedChoice}. Click Finish to complete the wizard.&lt;/p&gt;</fieldText>
<fieldText>&lt;p&gt;&lt;strong&gt;Records
Updated!&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;All units in
{!recordId.Name__c} have been updated to {!SelectedChoice}. Click Finish to complete
the wizard.&lt;/p&gt;</fieldText>
<fieldType>DisplayText</fieldType>
</fields>
<showFooter>true</showFooter>
Expand All @@ -409,7 +412,13 @@
<allowPause>false</allowPause>
<fields>
<name>Error_Screen_Text</name>
<fieldText>&lt;p&gt;There has been an error in the flow when it attempting to update records.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Click the Previous button below to go back and try again. If the problem persists, contact your &lt;span style=&quot;background-color: rgb(255, 255, 255); color: rgb(68, 68, 68);&quot;&gt;Salesforce administrator with &lt;/span&gt;the fault message below.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Fault Message:&lt;/p&gt;&lt;p&gt;{!$Flow.FaultMessage}&lt;/p&gt;</fieldText>
<fieldText>&lt;p&gt;There has been an error in the flow when it attempting to update
records.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Click the Previous button
below to go back and try again. If the problem persists, contact your &lt;span
style=&quot;background-color: rgb(255, 255, 255); color: rgb(68, 68,
68);&quot;&gt;Salesforce administrator with &lt;/span&gt;the fault message
below.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Fault
Message:&lt;/p&gt;&lt;p&gt;{!$Flow.FaultMessage}&lt;/p&gt;</fieldText>
<fieldType>DisplayText</fieldType>
</fields>
<showFooter>true</showFooter>
Expand All @@ -425,7 +434,13 @@
<allowPause>false</allowPause>
<fields>
<name>Copy_1_of_Has_Allocated_Units_Text</name>
<fieldText>&lt;p&gt;Block/Sub Block &lt;strong&gt;&lt;em&gt;{!recordId.Name__c}&lt;/em&gt;&lt;/strong&gt; has at least 1 unit that is housing an animal, and is allocated. &lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Please make arrangements to move the animals out of any units in this Block/Sub Block.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Click &lt;strong&gt;Finish&lt;/strong&gt; to Exit&lt;/p&gt;</fieldText>
<fieldText>&lt;p&gt;Block/Sub Block
&lt;strong&gt;&lt;em&gt;{!recordId.Name__c}&lt;/em&gt;&lt;/strong&gt; has at least 1
unit that is housing an animal, and is allocated.
&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Please make arrangements to move the
animals out of any units in this Block/Sub
Block.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Click
&lt;strong&gt;Finish&lt;/strong&gt; to Exit&lt;/p&gt;</fieldText>
<fieldType>DisplayText</fieldType>
</fields>
<showFooter>true</showFooter>
Expand All @@ -444,7 +459,8 @@
</connector>
<fields>
<name>Start_Screen_Text</name>
<fieldText>&lt;p&gt;To change the status of the current Block or Sub Block and all its units, select an option below&lt;/p&gt;</fieldText>
<fieldText>&lt;p&gt;To change the status of the current Block or Sub Block and all its
units, select an option below&lt;/p&gt;</fieldText>
<fieldType>DisplayText</fieldType>
</fields>
<fields>
Expand All @@ -457,7 +473,10 @@
<inputsOnNextNavToAssocScrn>UseStoredValues</inputsOnNextNavToAssocScrn>
<isRequired>false</isRequired>
</fields>
<helpText>&lt;p&gt;This wizard allows you to update the status for all units within a single block at the same time. &lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;For example if the block needs to be closed for maintenance, you can use this to update the whole block to unavailable.&lt;/p&gt;</helpText>
<helpText>&lt;p&gt;This wizard allows you to update the status for all units within a single
block at the same time. &lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;For example if
the block needs to be closed for maintenance, you can use this to update the whole block
to unavailable.&lt;/p&gt;</helpText>
<showFooter>true</showFooter>
<showHeader>true</showHeader>
</screens>
Expand Down Expand Up @@ -506,31 +525,31 @@
<isCollection>true</isCollection>
<isInput>false</isInput>
<isOutput>false</isOutput>
<objectType>Locations__c</objectType>
<objectType>animalshelters__Locations__c</objectType>
</variables>
<variables>
<name>currentItem_Filter_for_Allocated_Records</name>
<dataType>SObject</dataType>
<isCollection>false</isCollection>
<isInput>false</isInput>
<isOutput>false</isOutput>
<objectType>Locations__c</objectType>
<objectType>animalshelters__Locations__c</objectType>
</variables>
<variables>
<name>currentItem_Filter_for_MultiAnimal_Units</name>
<dataType>SObject</dataType>
<isCollection>false</isCollection>
<isInput>false</isInput>
<isOutput>false</isOutput>
<objectType>Locations__c</objectType>
<objectType>animalshelters__Locations__c</objectType>
</variables>
<variables>
<name>recordId</name>
<dataType>SObject</dataType>
<isCollection>false</isCollection>
<isInput>true</isInput>
<isOutput>false</isOutput>
<objectType>Locations__c</objectType>
<objectType>animalshelters__Locations__c</objectType>
</variables>
<variables>
<name>SelectedChoice</name>
Expand All @@ -545,14 +564,14 @@
<isCollection>false</isCollection>
<isInput>false</isInput>
<isOutput>false</isOutput>
<objectType>Locations__c</objectType>
<objectType>animalshelters__Locations__c</objectType>
</variables>
<variables>
<name>updatedLocationRecords</name>
<dataType>SObject</dataType>
<isCollection>true</isCollection>
<isInput>false</isInput>
<isOutput>false</isOutput>
<objectType>Locations__c</objectType>
<objectType>animalshelters__Locations__c</objectType>
</variables>
</Flow>
</Flow>
Loading

0 comments on commit 451f9dc

Please sign in to comment.