-
How can I test this class in Salesforce?
I am creating a new Content Link on Service Appointment inserting from the parent work order and I am struggling on how I would write a test against this.
trigger LinkWorkOrderContentToServiceAppointment on ServiceAppointment (after insert) {
List<ContentDocumentLink> CDLtoUpdate = new List<ContentDocumentLink>();
Set<ID> TicketIDs = new Set<ID>();for (ServiceAppointment SA : Trigger.new) {
TicketIDs.add(SA.Master_Ticket__c);
}List<ContentDocumentLink> ContentDocumentLinks = new List<ContentDocumentLink>([select id,ContentDocumentId,LinkedEntityId from ContentDocumentLink where LinkedEntityId in:TicketIDs]);
for (ContentDocumentLink CDL : ContentDocumentLinks){
for (ServiceAppointment SA : Trigger.new){
if(CDL.LinkedEntityId == SA.Master_Ticket__c){
if(CDLtoUpdate.size()>199){
insert CDLtoUpdate;
CDLtoUpdate.clear();
}
ContentDocumentLink NCDL = new ContentDocumentLink(ContentDocumentId = CDL.ContentDocumentId, LinkedEntityId = SA.Id, ShareType ='V', Visibility = 'AllUsers');
CDLtoUpdate.add(NCDL);
}
}
}
if(CDLtoUpdate.size() > 0){
insert CDLtoUpdate;
CDLtoUpdate.clear();
}}
Log In to reply.
Popular Salesforce Blogs
A Small Guide On Salesforce Integration: Benefits | Types | Perks
As businesses expand their operations, they often need help to keep up with the increasing workload. From managing customer information to tracking sales leads, the…
Salesforce CPQ Spring '21 Release Features
Salesforce CPQ aka Configure, Price, Quote Software is a cloud-based sales tool that provides accurate pricing information with different product configuration scenarios. CPQ reduces the…
Creating and Populating a Wrapper in Apex
As Apex is a statically typed language, you must choose only one object type per list to iterate. What if you want to iterate an…
Popular Salesforce Videos
Work With Custom Lightning Components | Salesforce Tutorial
Creating a custom Lightning component requires programming skills. Or, you can install an existing Lightning component from the AppExchange. You can create a custom Lightning…
Integrate Salesforce with External System using REST API
In this video, Path to Code explains the following topics: - What is API? - Introduction to REST API - Using cURL to consume Rest…
Code Review in Salesforce
Code Review and Code Quality in Salesforce 0:00 Introduction 0:44 What is code review? 1:22 Why we need code review 3:33 Basic code review 4:12…