Loading

Salesforce Error: "Service Report not allowed for this record.: []" Running Apex Test Class That Creates a Test Service Report Record

게시 일자: Jan 7, 2026
상세 설명

During the execution of a Salesforce Apex test class that involves creating a test Service Report record, the test fails and returns the following error message:

"Service Report not allowed for this record.: []"

This issue occurs specifically when running the tests that attempt to generate Service Report records.

솔루션

The Salesforce error that the"Service Report not allowed for this record" occurs because the ParentId (for example, a Work Order) does not have a valid ServiceReportTemplateId assigned, or the org does not have an active standard Service Report Template.

To fix this issue, ensure that the ServiceReportTemplateId is properly assigned to the parent record of the test Service Report.

Example Code:

// Inserting Test Work Order
WorkOrder wo = new WorkOrder();
wo.Subject = 'Test Subject';
wo.ServiceReportTemplateId = <Insert_ServiceReportTemplateID>; // Assign Service Report Template Id if no standard template is active in the org
insert wo;

// Querying the created Work Order
WorkOrder workOrder = [SELECT Id FROM WorkOrder WHERE Subject = 'Test Subject' LIMIT 1];

// Inserting test Service Report
ServiceReport sr = new ServiceReport();
sr.ParentId = workOrder.Id; // Set ParentId to the newly created Work Order Id
insert sr;

Note: This sample code is provided for illustration purposes to explain the issue and resolution.

Knowledge 기사 번호

005131271

 
로드 중
Salesforce Help | Article