-
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

How to Choose The Best Healthcare CRM?
With the rise of consumerism, there is a competitive increase in the healthcare market. Patients have a lot of choices when it comes to picking…

To Do Checklist Before Code Commit In Production
TO DO CHECKLIST BEFORE CODE COMMIT IN PRODUCTION Proper commenting in code (Test Class, Apex Class, Trigger, Vf page), if you modified or create new…

How Salesforce is Responding to The COVID-19 Pandemic?
Governments and businesses worldwide have begun their COVID-19 vaccination programs to protect citizens from the continuously mutating virus, although they have grappled with multiple obstacles…
Popular Salesforce Videos
Mocking Apex Tests: Salesforce Tutorial
In this Video Leonardo Berardino talks about the following: Mocking Apex Tests and Apex Mock Examples Unit Tests x Integration Tests How to create unit…
5 Pillars of a Successful Salesforce DevOps Process
Looking to improve your release and issue resolution times using Salesforce DevOps methodologies? DevOps is a software development and delivery process enabling seamless collaboration between…
Discover Lightning Web Components | Salesforce Tutorial
Watch this Salesforce tutorial. After completing this unit, you’ll be able to: Explain the Lightning Web Components programming model. List the benefits of using Lightning…