You need to sign in to do that
Don't have an account?
Connor Cain
Apex Test Class for ContentDownloadHandler method
Ive created a Apex class that creates a record when a document is downloaded to have record that someone downloaded it, here is the code:
how would I write a Test Class to simulate a User Downloading a File?
public class *method* implements Sfc.ContentDownloadHandlerFactory { public Sfc.ContentDownloadHandler getContentDownloadHandler(List<ID> ids, Sfc.ContentDownloadContext context) { Sfc.ContentDownloadHandler contentDownloadHandler = new Sfc.ContentDownloadHandler(); customObject__c um = new customObject__c(); um.User_Name__c = UserInfo.getName(); um.Access_Date__c = datetime.now(); um.Record_ID__c = ids.get(0); um.Type__c = 'File Download'; insert um; contentDownloadHandler.isDownloadAllowed = true; return contentDownloadHandler; } }
how would I write a Test Class to simulate a User Downloading a File?
All Answers
public class UserViewFilesTest {
public static testMethod void testforFile(){
Account testAccount = new Account(Name='TestAccount');
insert testAccount;
Attachment testAttachment = new Attachment(
Name='test12345',
Description='testDescription',
ParentId=testAccount.Id);
Blob bodyBlob = Blob.valueOf('Unit Test Attachment Body');
testAttachment.body=bodyBlob;
insert testAttachment;
ContentVersion testContent = new ContentVersion(
Title='test12345',
Description='testDescription',
ContentLocation = 'S',
PathOnClient = 'test12345',
VersionData = bodyBlob);
insert testContent;
ContentDocumentLink testLink = new ContentDocumentLink(
ContentDocumentId = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE Id =:testContent.Id].ContentDocumentId,
LinkedEntityId = testAccount.Id,
ShareType = 'V');
insert testLink;
UserViewFile f = new UserViewFile();
f.getContentDownloadHandler(new List<Id>{testLink.Id}, null);
}
}
Error: Line 28 Invalid type: UserViewFile