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.
005131271

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.