-
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

Bric API - Business card scanner API
Pass card images and get accurate results in JSON. Most CRM / ERP software requires inputting customer/vendor details into the software and a major source…

How Salesforce Technology is Changing Marketing and Customer Engagement
How Technology Will Change Marketing and Customer Engagement The application of artificial intelligence or AI to many business processes seems limitless now that we continue…
Popular Salesforce Videos
What is Audit Trail in Salesforce?
Audit Trails helps to track the recent setup changes that you and other administrators have made to your organization. Watch this video to learn about…
Which Objects are in the Salesforce Sales Cloud and Service Cloud?
In this video, We run through some of these diagrams. We'll also discuss some of the particular objects that you'll need to become familiar with as you…
Salesforce Tutorial Video | Salesforce Walkthroughs
Salesforce Walkthroughs is a new feature for Summer '20 which allows myTrailhead customers to create a series of up to 10 connected prompts to direct…