Skip to content

Commit

Permalink
Merge pull request #160
Browse files Browse the repository at this point in the history
* Platform Event Created

* Update Animal_Shelter_Starter.permissionset-meta.xml

* Trigger Flows for PE

* Controller Created

* Controller Test Class

* Badge Component

* Update animalBadge.js

* Added Test Component

* Updates

* Updates to PE

* Updates to Flow

* Removed Test Component

* Final Updates

* Update AnimalBadgeController.cls

* Final Updates

* Update animalBadge.css

* Update animalBadge.html
  • Loading branch information
cjrolfe authored Apr 5, 2024
1 parent b9d31ae commit 58f7771
Show file tree
Hide file tree
Showing 17 changed files with 511 additions and 0 deletions.
73 changes: 73 additions & 0 deletions force-app/main/default/classes/AnimalBadgeController.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* @File Name : AnimalBadgeController.cls
* @Description :
* @Author : Chris Rolfe (Salesforce)
* @Last Modified By :
* @Last Modified On :
* @Modification Log :
* Ver Date Author Modification
* 1.0 01/04/2024 Chris Rolfe (Salesforce) Initial Version
**/
public with sharing class AnimalBadgeController {

@AuraEnabled(cacheable=true)
public static Map<String, Boolean> getRelatedBadges(Id animalId) {
Map<String, Boolean> badges = new Map<String, Boolean>{
'Alert' => false,
'Condition' => false,
'Nutrition' => false,
'Exercise' => false,
'Treatment' => false,
'Vaccination' => false
};

// Check for Alerts with no end date
if(Schema.sObjectType.animalshelters__Animal_Alert__c.isAccessible() && Schema.sObjectType.animalshelters__Animal_Alert__c.fields.Animalshelters__End_Date_Time__c.isAccessible()) {
List<animalshelters__Animal_Alert__c> alerts = [SELECT Id
FROM animalshelters__Animal_Alert__c
WHERE animalshelters__Animal__c = :animalId
AND animalshelters__End_Date_Time__c = null
WITH SECURITY_ENFORCED];
// System.debug(alerts);
if(!alerts.isEmpty()) {
badges.put('Alert', true);
}
}

// Check for Condiitons that have no end date
if(Schema.sObjectType.animalshelters__Condition__c.isAccessible() && Schema.sObjectType.animalshelters__Condition__c.fields.Animalshelters__End_Date_Time__c.isAccessible()) {
List<animalshelters__Condition__c> conditions = [SELECT Id
FROM animalshelters__Condition__c
WHERE animalshelters__Animal__c = :animalId
AND animalshelters__End_Date_Time__c = null
WITH SECURITY_ENFORCED];
// System.debug(conditions);
if(!conditions.isEmpty()) {
badges.put('Condition', true);
}
}

// Check for Action Records and RecordTypes
if(Schema.sObjectType.animalshelters__Animal_Action__c.isAccessible() && Schema.sObjectType.animalshelters__Animal_Action__c.fields.animalshelters__Treatment_Type__c.isAccessible() && Schema.sObjectType.animalshelters__Animal_Action__c.fields.animalshelters__Action_Completed__c.isAccessible()) {
List<animalshelters__Animal_Action__c> actions = [SELECT Id, RecordType.Name, animalshelters__Treatment_Type__c
FROM animalshelters__Animal_Action__c
WHERE animalshelters__Animal__c = :animalId
AND animalshelters__Action_Completed__c = false
WITH SECURITY_ENFORCED];
// System.debug(actions);
for(animalshelters__Animal_Action__c action : actions) {
if(action.RecordType.Name == 'Nutrition') {
badges.put('Nutrition', true);
} else if(action.RecordType.Name == 'Exercise'){
badges.put('Exercise', true);
} else if(action.RecordType.Name == 'Treatment' && action.animalshelters__Treatment_Type__c == 'Vaccination'){
badges.put('Vaccination', true);
} else if(action.RecordType.Name == 'Treatment' && action.animalshelters__Treatment_Type__c != 'Vaccination'){
badges.put('Treatment', true);
}
}
//System.debug(badges);
}
return badges;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<status>Active</status>
</ApexClass>
51 changes: 51 additions & 0 deletions force-app/main/default/classes/AnimalBadgeControllerTest.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@isTest
private class AnimalBadgeControllerTest {

@IsTest static void testNoBadges() {
// Set Up Test Data
animalshelters__Animal__c testAnimal = new animalshelters__Animal__c(animalshelters__Animal_Name__c = 'Test Animal', animalshelters__Date_of_Arrival__c = Date.today());
insert testAnimal;

//Test with no badges
Test.startTest();
Map<String, Boolean> badges = AnimalBadgeController.getRelatedBadges(testAnimal.Id);
Test.stopTest();

//Verify Results
System.assertEquals(false, badges.get('Alert'), 'Expected no alert');
System.assertEquals(false, badges.get('Condition'), 'Expected no Condition');
System.assertEquals(false, badges.get('Nutrition'), 'Expected no Nutrition');
System.assertEquals(false, badges.get('Exercise'), 'Expected no Exercise');
System.assertEquals(false, badges.get('Treatment'), 'Expected no Treatment');
}

@IsTest static void testWithBadges() {
// Set Up Test Data
animalshelters__Animal__c testAnimal = new animalshelters__Animal__c(animalshelters__Animal_Name__c = 'Test Animal', animalshelters__Date_of_Arrival__c = Date.today());
insert testAnimal;

animalshelters__Animal_Alert__c alert = new animalshelters__Animal_Alert__c(animalshelters__Animal__c = testAnimal.Id, animalshelters__Start_Date_Time__c = Date.today(), animalshelters__Type__c = 'General', animalshelters__Alert_Message__c = 'Test');
animalshelters__Condition__c condition = new animalshelters__Condition__c(animalshelters__Animal__c = testAnimal.Id, animalshelters__Start_Date__c = Date.today());
insert alert;
insert condition;

//Create a dummy record type for Action
Id recordTypeId = Schema.SObjectType.animalshelters__Animal_Action__c.getRecordTypeInfosByName().get('Exercise').getRecordTypeId();
animalshelters__Animal_Action__c action = new animalshelters__Animal_Action__c(animalshelters__Animal__c = testAnimal.Id, animalshelters__Date_Time_of_Action__c= Date.today(), animalshelters__Description__c = 'Test', RecordTypeId = recordTypeId);
insert action;

//Test with Badges
Test.startTest();
Map<String, Boolean> badges = AnimalBadgeController.getRelatedBadges(testAnimal.Id);
Test.stopTest();

//Verify Results
System.assertEquals(true, badges.get('Alert'), 'Expected an alert');
System.assertEquals(true, badges.get('Condition'), 'Expected a Condition');
System.assertEquals(false, badges.get('Nutrition'), 'Expected no Nutrition');
System.assertEquals(true, badges.get('Exercise'), 'Expected an Exercise');
System.assertEquals(false, badges.get('Treatment'), 'Expected no Treatment');

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,12 @@
<type>Facet</type>
</flexiPageRegions>
<flexiPageRegions>
<itemInstances>
<componentInstance>
<componentName>animalBadge</componentName>
<identifier>animalshelters_animalBadge</identifier>
</componentInstance>
</itemInstances>
<itemInstances>
<componentInstance>
<componentInstanceProperties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<description>[Animal Shelter Starter] - Creates a Platform Event for Badge Update on record create or update</description>
<environments>Default</environments>
<interviewLabel>Animal Action - Create Platform Event {!$Flow.CurrentDateTime}</interviewLabel>
<label>Animal Action - Create Platform Event</label>
<processMetadataValues>
<name>BuilderType</name>
<value>
<stringValue>LightningFlowBuilder</stringValue>
</value>
</processMetadataValues>
<processMetadataValues>
<name>CanvasMode</name>
<value>
<stringValue>AUTO_LAYOUT_CANVAS</stringValue>
</value>
</processMetadataValues>
<processMetadataValues>
<name>OriginBuilderType</name>
<value>
<stringValue>LightningFlowBuilder</stringValue>
</value>
</processMetadataValues>
<processType>AutoLaunchedFlow</processType>
<recordCreates>
<name>Create_Platform_Event</name>
<label>Create Platform Event</label>
<locationX>176</locationX>
<locationY>323</locationY>
<inputAssignments>
<field>Record_ID__c</field>
<value>
<elementReference>$Record.Animal__r.Id</elementReference>
</value>
</inputAssignments>
<inputAssignments>
<field>Update_Type__c</field>
<value>
<stringValue>Action</stringValue>
</value>
</inputAssignments>
<object>Badge_Update_Event__e</object>
<storeOutputAutomatically>true</storeOutputAutomatically>
</recordCreates>
<start>
<locationX>50</locationX>
<locationY>0</locationY>
<connector>
<targetReference>Create_Platform_Event</targetReference>
</connector>
<object>Animal_Action__c</object>
<recordTriggerType>CreateAndUpdate</recordTriggerType>
<triggerType>RecordAfterSave</triggerType>
</start>
<status>Active</status>
</Flow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<description>[Animal Shelters Starter] - Creates a Platform Event for Badge Update when Alert records are Created or Updated</description>
<environments>Default</environments>
<interviewLabel>Animal Alert - Create Platform Event {!$Flow.CurrentDateTime}</interviewLabel>
<label>Animal Alert - Create Platform Event</label>
<processMetadataValues>
<name>BuilderType</name>
<value>
<stringValue>LightningFlowBuilder</stringValue>
</value>
</processMetadataValues>
<processMetadataValues>
<name>CanvasMode</name>
<value>
<stringValue>AUTO_LAYOUT_CANVAS</stringValue>
</value>
</processMetadataValues>
<processMetadataValues>
<name>OriginBuilderType</name>
<value>
<stringValue>LightningFlowBuilder</stringValue>
</value>
</processMetadataValues>
<processType>AutoLaunchedFlow</processType>
<recordCreates>
<name>Create_Platform_Event</name>
<label>Create Platform Event</label>
<locationX>176</locationX>
<locationY>323</locationY>
<inputAssignments>
<field>Record_ID__c</field>
<value>
<elementReference>$Record.Animal__r.Id</elementReference>
</value>
</inputAssignments>
<inputAssignments>
<field>Update_Type__c</field>
<value>
<stringValue>Alert</stringValue>
</value>
</inputAssignments>
<object>Badge_Update_Event__e</object>
<storeOutputAutomatically>true</storeOutputAutomatically>
</recordCreates>
<start>
<locationX>50</locationX>
<locationY>0</locationY>
<connector>
<targetReference>Create_Platform_Event</targetReference>
</connector>
<object>Animal_Alert__c</object>
<recordTriggerType>CreateAndUpdate</recordTriggerType>
<triggerType>RecordAfterSave</triggerType>
</start>
<status>Active</status>
</Flow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<description>[Animal Shelter Starter] - Creates a Platform Event for Badge Update on record create or update</description>
<environments>Default</environments>
<interviewLabel>Condition - Create Platform Event {!$Flow.CurrentDateTime}</interviewLabel>
<label>Condition - Create Platform Event</label>
<processMetadataValues>
<name>BuilderType</name>
<value>
<stringValue>LightningFlowBuilder</stringValue>
</value>
</processMetadataValues>
<processMetadataValues>
<name>CanvasMode</name>
<value>
<stringValue>AUTO_LAYOUT_CANVAS</stringValue>
</value>
</processMetadataValues>
<processMetadataValues>
<name>OriginBuilderType</name>
<value>
<stringValue>LightningFlowBuilder</stringValue>
</value>
</processMetadataValues>
<processType>AutoLaunchedFlow</processType>
<recordCreates>
<name>Create_Platform_Event</name>
<label>Create Platform Event</label>
<locationX>176</locationX>
<locationY>323</locationY>
<inputAssignments>
<field>Record_ID__c</field>
<value>
<elementReference>$Record.Animal__r.Id</elementReference>
</value>
</inputAssignments>
<inputAssignments>
<field>Update_Type__c</field>
<value>
<stringValue>Condition</stringValue>
</value>
</inputAssignments>
<object>Badge_Update_Event__e</object>
<storeOutputAutomatically>true</storeOutputAutomatically>
</recordCreates>
<start>
<locationX>50</locationX>
<locationY>0</locationY>
<connector>
<targetReference>Create_Platform_Event</targetReference>
</connector>
<object>Condition__c</object>
<recordTriggerType>CreateAndUpdate</recordTriggerType>
<triggerType>RecordAfterSave</triggerType>
</start>
<status>Active</status>
</Flow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createElement } from 'lwc';
import AnimalBadge from 'c/animalBadge';

describe('c-animal-badge', () => {
afterEach(() => {
// The jsdom instance is shared across test cases in a single file so reset the DOM
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
});

it('TODO: test case generated by CLI command, please fill in test logic', () => {
// Arrange
const element = createElement('c-animal-badge', {
is: AnimalBadge
});

// Act
document.body.appendChild(element);

// Assert
// const div = element.shadowRoot.querySelector('div');
expect(1).toBe(1);
});
});
13 changes: 13 additions & 0 deletions force-app/main/default/lwc/animalBadge/animalBadge.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.badge {
display: inline-block;
padding: 2px;
border-radius: 5px;
color: white;
margin-right: 10px;
}
.alert { background-color: red; }
.condition { background-color: grey; }
.nutrition { background-color: green; }
.exercise { background-color: orange; }
.treatment { background-color: blue; }
.vaccination { background-color: pink; }
24 changes: 24 additions & 0 deletions force-app/main/default/lwc/animalBadge/animalBadge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<template>
<lightning-card title="Animal Status Indicators" icon-name="custom:custom26">
<div class="slds-var-m-around_medium">
<template if:true={badges.Alert}>
<span class="badge alert">Alert</span>
</template>
<template if:true={badges.Condition}>
<span class="badge condition">Condition</span>
</template>
<template if:true={badges.Nutrition}>
<span class="badge nutrition">Nutrition</span>
</template>
<template if:true={badges.Exercise}>
<span class="badge exercise">Exercise</span>
</template>
<template if:true={badges.Treatment}>
<span class="badge treatment">Treatment</span>
</template>
<template if:true={badges.Vaccination}>
<span class="badge vaccination">Vaccination</span>
</template>
</div>
</lightning-card>
</template>
Loading

0 comments on commit 58f7771

Please sign in to comment.