function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RabRab 

Test Class Issues

Hello,

I was wondering if someone could please help me write a test class.

This is my trigger:
trigger AssignedResourceTrigger on AssignedResource (after delete) {
    if(trigger.isafter && trigger.isdelete) {
        map<string,object> params = new map<string,object>();
        params.put('AssignedResources', trigger.new);
        flow.Interview.Add_Assigned_UserIds_to_the_Service_Appointment_Delete_Trigger myFlow = new flow.Interview.Add_Assigned_UserIds_to_the_Service_Appointment_Delete_Trigger(params);
        myFlow.start();
    }
}


This is currently my test class code:

@isTest
private class AssignedResourceTestClass {
    @isTest static void validateAssignedResource() {
		// data creation
		Id serviceAgentRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Service Agent').getRecordTypeId();

		Account newPersonAccount = new Account();

		newPersonAccount.put('FirstName', 'Test');
		newPersonAccount.put('LastName', 'Agent');
		newPersonAccount.RecordTypeId = serviceAgentRecordTypeId;

		insert newPersonAccount;

		ServiceAppointment sa = new ServiceAppointment(
				ParentRecordId = newPersonAccount.id
		);

		insert sa;


		//retrieve service appointment
		Test.startTest();

		Test.stopTest();

		// assert statements

	
	}
		
}
I am unsure how to proceed. I am trying to assign a resource to a service appointment, then delete the assigned resource without deleting the other resources from the service appointment. Can anyone please help.
Suraj Tripathi 47Suraj Tripathi 47
Hi,

As you have applied trigger after delete, you have to perform delete operation in your test class. You have to DELETE the required assigned resource. Before deleting please make sure to create all required records that are required in the trigger.

If it helps please mark it as Best Answer so that other people would take reference from it.

Thanks & Regards
Suraj Tripathi