trigger ServiceReporttoSA on ServiceReport (after insert) {
for (ServiceReport SR: Trigger.new) {
ServiceAppointment SA = [select Id FROM ServiceAppointment WHERE ID
=:SR.parentId];
SA.servicereportCompleted__c = true;
update SA;
}
}
Test Class
@isTest
public class TestServiceReporttoSA {
@isTest static void TestSR(){
//Test data
Account a = new Account(Name = 'testAccountSA',
BillingPostalCode = '83059',
BillingCountry = 'Deutschland');
insert a;
Contact c = new Contact(FirstName = 'TESTOS',
LastName = 'TEstmann',
AccountId = a.id);
insert c;
Product2 e =new Product2 (Name = 'Top AG', VK_netto__c = 250,
created_by__c = 'bla');
insert e;
Pricebookentry f = [Select Id From PriceBookEntry where Product2Id = :e.Id and PriceBook2Id= :Test.getStandardPricebookId()];
f = new Pricebookentry (Id = f.Id,
UnitPrice = 250,
usestandardprice = false,
isactive = true);
update f;
Opportunity g = new Opportunity (Name = 'testOpp',
AccountId = a.Id,
Amount = 250,
StageName = 'new',
CloseDate = date.today(),
Category__c = 'Sonstige',
created_by__c = 'bla');
insert g;
update a;
OpportunityLineItem h = new OpportunityLineItem ( OpportunityId = g.Id,
Quantity = 1,
TotalPrice = 250,
PricebookentryId = f.Id);
insert h;
Case cas = new Case (AccountId = a.Id,
STATUS = 'New',
Origin = 'Homepage',
created_by__c = 'bla');
insert cas;
WorkOrder WO = new WorkOrder (AccountId = a.Id,
CaseId = cas.Id);
insert WO;
ServiceAppointment SA = new ServiceAppointment (Case__c = cas.Id,
ParentRecordId = WO.Id);
insert SA;
//System.AssertEquals(a.Id, g.AccountID);
//
//
//SR = TestSR.createServiceReport();
//ServiceReport SR = new ServiceReport (ServiceReport = SR.ID, parentid = SA.Id);
System.AssertEquals( );
}
}
Can someone help me to add a Service Report for this test class?
assertEquals()
parameters. What error or issue did you encounter when you created theServiceReport
in your commented-out code?