function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gaurav Chauhan 16Gaurav Chauhan 16 

Service Report Test Class Creation - FSL

How to create Test Class for trigger on 'Service Report' object (FSL) ?
Best Answer chosen by Gaurav Chauhan 16
Raj VakatiRaj Vakati
Like this
 
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;

        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;

    
	
	
ContentVersion contentVersion = new ContentVersion(
  Title = 'Penguins',
  PathOnClient = 'Penguins.jpg',
  VersionData = Blob.valueOf('Test Content'),
  IsMajorVersion = true
);
insert contentVersion;    
List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];

//create ContentDocumentLink  record 
ContentDocumentLink cdl = New ContentDocumentLink();
cdl.LinkedEntityId = WO.id;
cdl.ContentDocumentId = documents[0].Id;
cdl.shareType = 'V';
insert cdl;


ServiceReport sr = new ServiceReport();
sr.ContentVersionDocumentId = documents[0].Id ;
sr.DocumentBody = Blob.valueOf('Test Content') ; 
sr.DocumentContentType ='application/pdf';
sr.DocumentName='Test';
sr.ParentId = WO.Id ; 
insert sr ;

 

All Answers

Raj VakatiRaj Vakati
Like this
 
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;

        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;

    
	
	
ContentVersion contentVersion = new ContentVersion(
  Title = 'Penguins',
  PathOnClient = 'Penguins.jpg',
  VersionData = Blob.valueOf('Test Content'),
  IsMajorVersion = true
);
insert contentVersion;    
List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];

//create ContentDocumentLink  record 
ContentDocumentLink cdl = New ContentDocumentLink();
cdl.LinkedEntityId = WO.id;
cdl.ContentDocumentId = documents[0].Id;
cdl.shareType = 'V';
insert cdl;


ServiceReport sr = new ServiceReport();
sr.ContentVersionDocumentId = documents[0].Id ;
sr.DocumentBody = Blob.valueOf('Test Content') ; 
sr.DocumentContentType ='application/pdf';
sr.DocumentName='Test';
sr.ParentId = WO.Id ; 
insert sr ;

 
This was selected as the best answer
Gaurav Chauhan 16Gaurav Chauhan 16
Thank You Raj:-) It worked with little changes as per my requirement.
Dave Durant 23Dave Durant 23
Did you test that code, Raj? I don't think we can set/update ServiceReport.ContentVersionDocumentId.