You need to sign in to do that
Don't have an account?
Travis16
Test class on ContentDocumentLink
Trying to write a test class for the following trigger that gives access to community members for documents under the quotes object. I am just not sure how to test/check in the test class.
Trigger
trigger shareFilesWithCommunityUsers on ContentDocumentLink(before insert){
Schema.DescribeSObjectResult r = Quote.sObjectType.getDescribe();
String keyPrefix = r.getKeyPrefix();
for(ContentDocumentLink cdl:trigger.new){
if((String.valueOf(cdl.LinkedEntityId)).startsWith(keyPrefix)){
cdl.ShareType = 'I';
cdl.Visibility = 'AllUsers';
}
}
}
Test Class
@IsTest
Public class TestShareFilesWithCommunityUsers {
static testmethod void testmethod1(){
//Create 2 accounts
List<Account> accounts = new List<Account>();
Account accA = bg_Account_Test_Utils.createAccount('Influencer', 'Account A');
accounts.add(accA);
insert accounts;
//Create 2 contacts, linked to the accounts
List<Contact> contacts = new List<Contact>();
Contact conA = bg_Contact_Test_Utils.createContact('Test', 'Contact A', accA.Id);
contacts.add(conA);
insert contacts;
//Create a project
Project__c project = bg_Project_Test_Utils.createProject('Test Project 1', 'Education', 'Tender Phase', 'Leeds', 'LS61QF', accA.Id, conA.Id, 'New build project');
insert project;
List<Opportunity> opps = new List<Opportunity>();
Opportunity wonOpp = bg_Opportunity_Test_Utils.createOpportunity('Controlled Environments', 'Opportunity 1', accA.Id, 'Outline Specification', project.Id, Date.Today() + 30);
opps.add(wonOpp);
insert opps;
Quote Q = New Quote(Name='Test Quote', OpportunityId=WonOpp.Id);
insert Q;
ContentDocumentLink contentlink=new ContentDocumentLink();
contentlink.LinkedEntityId=q.id;
contentlink.ShareType= 'I';
contentlink.LinkedEntityId = q.Id;
contentlink.Visibility = 'AllUsers';
insert contentlink;
}
}
Sorry Still Trying to Wrap my head around apex.
Trigger
trigger shareFilesWithCommunityUsers on ContentDocumentLink(before insert){
Schema.DescribeSObjectResult r = Quote.sObjectType.getDescribe();
String keyPrefix = r.getKeyPrefix();
for(ContentDocumentLink cdl:trigger.new){
if((String.valueOf(cdl.LinkedEntityId)).startsWith(keyPrefix)){
cdl.ShareType = 'I';
cdl.Visibility = 'AllUsers';
}
}
}
Test Class
@IsTest
Public class TestShareFilesWithCommunityUsers {
static testmethod void testmethod1(){
//Create 2 accounts
List<Account> accounts = new List<Account>();
Account accA = bg_Account_Test_Utils.createAccount('Influencer', 'Account A');
accounts.add(accA);
insert accounts;
//Create 2 contacts, linked to the accounts
List<Contact> contacts = new List<Contact>();
Contact conA = bg_Contact_Test_Utils.createContact('Test', 'Contact A', accA.Id);
contacts.add(conA);
insert contacts;
//Create a project
Project__c project = bg_Project_Test_Utils.createProject('Test Project 1', 'Education', 'Tender Phase', 'Leeds', 'LS61QF', accA.Id, conA.Id, 'New build project');
insert project;
List<Opportunity> opps = new List<Opportunity>();
Opportunity wonOpp = bg_Opportunity_Test_Utils.createOpportunity('Controlled Environments', 'Opportunity 1', accA.Id, 'Outline Specification', project.Id, Date.Today() + 30);
opps.add(wonOpp);
insert opps;
Quote Q = New Quote(Name='Test Quote', OpportunityId=WonOpp.Id);
insert Q;
ContentDocumentLink contentlink=new ContentDocumentLink();
contentlink.LinkedEntityId=q.id;
contentlink.ShareType= 'I';
contentlink.LinkedEntityId = q.Id;
contentlink.Visibility = 'AllUsers';
insert contentlink;
}
}
Sorry Still Trying to Wrap my head around apex.
All Answers