テストサービスレポートレコードを作成する Apex テストクラスの実行中に、テストが失敗して次のエラーが返されます。
「サービスレポートは、このレコードでは使用できません。: []」
この問題は、特にサービスレポートレコードを生成しようとするテストの実行時に発生します。
ParentId (作業指示など) に有効な ServiceReportTemplateId が割り当てられていないか、組織に有効な標準サービスレポートテンプレートがないため、「このレコードのサービスレポートは許可されていません」という Salesforce エラーが発生します。
この問題を修正するには、ServiceReportTemplateId がテストサービスレポートの親レコードに適切に割り当てられていることを確認します。
サンプルコード:
// 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;
注意: このサンプルコードは問題と解決方法を説明するために提供されています。
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.