3

In Field Service Lightning I have a Trigger on ServiceReport which sends an email with attachment coming from ContentVersion.

This is the Test class I have written.

@isTest

private class testCreateServiceReport{

     static testMethod void validateWO() {

     WorkOrder wo = new WorkOrder();

     wo.subject = 'Testing';

     insert wo;

     ServiceAppointment sa = new ServiceAppointment();

     sa.ParentRecordId = wo.Id;

     sa.EarliestStartTime = DateTime.now();

     sa.DueDate = DateTime.now();

     insert sa;

     List<ServiceReportLayout> srl = [Select Id FROM ServiceReportLayout];

     ServiceReport sr = new ServiceReport();

     sr.ParentId = sa.Id;

     sr.Template = srl[0].Id; //Need to check if there is a way to avoid srl[0] notation

     insert sr; //If I comment this the text result is pass. When I enable it I get too see the below mentioned error.

}

}

This is the error Methods defined as TestMethod do not support Web service callouts I know that we need to write Test Classes for code that involves web service callouts using setMock() but I dont understand in what way inserting ServiceReport is related to making a callout.

Any help on this will be really helpful.

5

Here is my theory.

From Salesforce docs here:

A service report is a PDF that summarizes a work order or service appointment and can be signed by customers and your team members. To control what shows up in your service reports, create service report templates.

So basically insertion of ServiceReport creates a PDF.

The way salesforce creates a pdf is via calling getContentAsPDF method.

Now from Winter 17, getContentAsPDF is treated as callout. As its a callout in test context one needs a mock.

The funny part is you cannot call getContentAsPDF in test context as mentioned here. So on top of my head, you wont be able to test insertion of ServiceReport

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.