1
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?

4
  • Right now, this code won't compile because of the missing assertEquals() parameters. What error or issue did you encounter when you created the ServiceReport in your commented-out code?
    – David Reed
    Commented Feb 12, 2019 at 15:47
  • The problem is, idk how to create the Service Report. With the trigger i will check if the service report is created for the Service Appointment. Commented Feb 12, 2019 at 15:49
  • So, i can not publish my trigger in production? Commented Feb 12, 2019 at 15:52
  • do you have a way to open an Case in SFDC? It could be an idea for now
    – m Peixoto
    Commented Feb 12, 2019 at 16:20

0

Browse other questions tagged .