Skip to content

Commit

Permalink
EDRD-309
Browse files Browse the repository at this point in the history
  • Loading branch information
ANLKMRK committed Dec 27, 2024
1 parent e423eb7 commit d77da27
Show file tree
Hide file tree
Showing 52 changed files with 2,046 additions and 3 deletions.
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;
}

}
}
}
}

}


}
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>
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');
}
}
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>
Loading

0 comments on commit d77da27

Please sign in to comment.