-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
2,046 additions
and
3 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
force-app/main/default/classes/ServiceAppointmentTriggerHandler.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/********************************************************************************************** | ||
* @Author: Accenture | ||
* @Date: 19/12/2024 | ||
* @Description: The purpose of this class is to create methods which can be used by different trigger event | ||
* @Revision(s): [Date] - [Change Reference] - [Changed By] - [Description] | ||
19-Dec24 EDRD-309 Accenture insert/update the name based on record | ||
***********************************************************************************************/ | ||
public with sharing class ServiceAppointmentTriggerHandler { | ||
public static Id recordTypeAccEDRD = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('EDRD_Committee').getRecordTypeId(); | ||
|
||
/** | ||
* @author: Accenture | ||
* @date: 19/12/2024 | ||
* @description: The purpose of this method is to insert the Name based on ParentRecord Name and EarliestStartTime | ||
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description] | ||
*/ | ||
public static void insertSAName(List<ServiceAppointment> saList){ | ||
if(!saList.isEmpty()){ | ||
Set<Id>saAccIds = new Set<Id>(); | ||
for(ServiceAppointment sapp : saList){ | ||
if(sapp.ParentRecordId != null ){ | ||
saAccIds.add(sapp.ParentRecordId); | ||
} | ||
} | ||
if(!saAccIds.isEmpty()){ | ||
|
||
Map<Id,Account> saAccMap = new Map<Id,Account>([Select Id,Name from Account | ||
where RecordTypeId =:recordTypeAccEDRD | ||
and id in :saAccIds]); | ||
if(!saAccMap.isEmpty()){ | ||
for(ServiceAppointment sapp : saList){ | ||
if(sapp.EarliestStartTime != null && saAccMap.containskey(sapp.ParentRecordId)){ | ||
Account acc = saAccMap.get(sapp.ParentRecordId); | ||
String trunDate = sapp.EarliestStartTime.format('yyyy-MM-dd'); | ||
String name = acc.Name + ' - ' + trunDate; | ||
sapp.EDRD_Name__c = name; | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
/** | ||
* @author: Accenture | ||
* @date: 19/12/2024 | ||
* @description: The purpose of this method is to update the Name based on ParentRecord Name and EarliestStartTime | ||
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description] | ||
*/ | ||
public static void updateSAName(List<ServiceAppointment> saList,Map<Id,ServiceAppointment> saOldMap){ | ||
if(!saList.isEmpty()){ | ||
Set<Id>saAccIds = new Set<Id>(); | ||
for(ServiceAppointment sapp : saList){ | ||
|
||
if(sapp.ParentRecordId != null && sapp.EarliestStartTime != saOldMap.get(sapp.Id).EarliestStartTime){ | ||
saAccIds.add(sapp.ParentRecordId); | ||
} | ||
} | ||
if(!saAccIds.isEmpty()){ | ||
Map<Id,Account> saAccMap = new Map<Id,Account>([Select Id,Name from Account | ||
where RecordTypeId =: recordTypeAccEDRD | ||
and Id in :saAccIds]); | ||
if(!saAccMap.isEmpty()){ | ||
for(ServiceAppointment sapp : saList){ | ||
if(sapp.EarliestStartTime != null && saAccMap.containskey(sapp.ParentRecordId)){ | ||
Account acc = saAccMap.get(sapp.ParentRecordId); | ||
String trunDate = sapp.EarliestStartTime.format('yyyy-MM-dd'); | ||
String name = acc.Name + ' - ' + trunDate; | ||
sapp.EDRD_Name__c = name; | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/ServiceAppointmentTriggerHandler.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>62.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
54 changes: 54 additions & 0 deletions
54
force-app/main/default/classes/ServiceAppointmentTriggerHandlerTest.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/********************************************************************************************** | ||
* @Author: Accenture | ||
* @Date: 26/12/2024 | ||
* @Description: The purpose of this class is cover the coverage for ServiceAppointmentTriggerHandler | ||
* @Revision(s): [Date] - [Change Reference] - [Changed By] - [Description] | ||
26-Dec24 EDRD-309 Accenture insert/update the name based on record | ||
***********************************************************************************************/ | ||
@isTest | ||
public class ServiceAppointmentTriggerHandlerTest { | ||
/** | ||
* @author: Accenture | ||
* @date: 26/12/2024 | ||
* @description: The purpose of this method is to cover Testcoverage of insertSAName | ||
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description] | ||
*/ | ||
@isTest | ||
public static void insertSANameTest(){ | ||
Account patientAccount = TestFactory.createEDRDACAccount('Ophthalmology Subcommittee'); | ||
insert patientAccount; | ||
DateTime startDateTime = DateTime.newInstance(2023, 8, 21, 14, 30, 0); | ||
DateTime endDateTime = DateTime.newInstance(2023, 10, 21, 14, 30, 0); | ||
ServiceAppointment sapRec = new ServiceAppointment(Status = 'Planned', ParentRecordId = patientAccount.Id,EarliestStartTime = startDateTime , DueDate = endDateTime ); | ||
test.startTest(); | ||
insert sapRec; | ||
test.stopTest(); | ||
Assert.areEqual([SELECT Id, EDRD_Name__c FROM ServiceAppointment WHERE Id =: sapRec.Id].get(0).EDRD_Name__c, 'Ophthalmology Subcommittee - 2023-08-21', 'Name matched'); | ||
Assert.areNotEqual([SELECT Id, EDRD_Name__c FROM ServiceAppointment WHERE Id =: sapRec.Id].get(0).EDRD_Name__c, Null, 'Name should not be null'); | ||
|
||
} | ||
|
||
/** | ||
* @author: Accenture | ||
* @date: 26/12/2024 | ||
* @description: The purpose of this method is to cover Testcoverage of updateSAName | ||
* @Modification Log: [Date] - [Change Reference] - [Changed By] - [Description] | ||
*/ | ||
@isTest | ||
public static void updateSANameTest(){ | ||
|
||
Account patientAccount = TestFactory.createEDRDACAccount('Ophthalmology Subcommittee'); | ||
insert patientAccount; | ||
DateTime startDateTime = DateTime.newInstance(2023, 8, 21, 14, 30, 0); | ||
DateTime endDateTime = DateTime.newInstance(2023, 10, 21, 14, 30, 0); | ||
DateTime updatedStartDateTime = DateTime.newInstance(2022, 8, 21, 14, 30, 0); | ||
ServiceAppointment sapRec = new ServiceAppointment(Status = 'Planned', ParentRecordId = patientAccount.Id,EarliestStartTime = startDateTime , DueDate = endDateTime ); | ||
insert sapRec; | ||
test.startTest(); | ||
sapRec.EarliestStartTime = updatedStartDateTime; | ||
update sapRec; | ||
test.stopTest(); | ||
Assert.areEqual([SELECT Id, EDRD_Name__c FROM ServiceAppointment WHERE Id =: sapRec.Id].get(0).EDRD_Name__c, 'Ophthalmology Subcommittee - 2022-08-21', 'Name matched'); | ||
Assert.areNotEqual([SELECT Id, EDRD_Name__c FROM ServiceAppointment WHERE Id =: sapRec.Id].get(0).EDRD_Name__c,Null, 'Name should not be null'); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/ServiceAppointmentTriggerHandlerTest.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>62.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
Oops, something went wrong.