Loading

Salesforce Field Service: Resolving the "Service Report not allowed for this record" Error in Apex Test Classes

Julkaisupäivä: May 30, 2026
Kuvaus

Error Description

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:

Service Report not allowed for this record.: []

This error occurs specifically when running Apex tests that attempt to insert Service Report records using a Work Order (or other supported parent object) as the parent record.

When This Error Occurs

This error is encountered in Apex test classes when:

  • A test Work Order or other parent record is created without assigning a valid ServiceReportTemplateId.
  • No standard Service Report Template is active in the org, meaning there is no default template to fall back on.
  • The test class does not explicitly assign a ServiceReportTemplateId to the parent record before attempting to insert the Service Report.
Ratkaisu

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-artikkelin numero

005131271

 
Ladataan
Salesforce Help | Article