You need to sign in to do that
Don't have an account?

Need help with a test class
Hi,
I've been trying to write a test class for this Apex class that is the controller for a lightning:fileUploader that uploads files and shows a list of the uploaded files. I've worked on it for a while now and nothing has worked so far. Can someone give me some assistance?
Apex class:
I've been trying to write a test class for this Apex class that is the controller for a lightning:fileUploader that uploads files and shows a list of the uploaded files. I've worked on it for a while now and nothing has worked so far. Can someone give me some assistance?
Apex class:
public class fileUploaderClass { @AuraEnabled public static List<ContentDocument> getFiles(string recordId){ List<ContentDocument> DocumentList = new List<ContentDocument>(); Set<Id> documentIds = new Set<Id>(); //store file ids List<ContentDocumentLink> cdl=[select id,LinkedEntityId,ContentDocumentId from ContentDocumentLink where LinkedEntityId=:recordId]; for(ContentDocumentLink cdLink:cdl){ documentIds.add(cdLink.ContentDocumentId); // Document ids } DocumentList = [select Id,Title,FileType,ContentSize,Description from ContentDocument where id IN: documentIds]; return DocumentList; } @AuraEnabled public static List<ContentDocument> UpdateFiles(string documentId,string title,string recordId){ system.debug('title: ' +title); ContentDocument cd = [select id,title from ContentDocument where Id=:documentId]; // Getting files from Parent record cd.Title = title; // Changing file Title with user entered title try{ update cd; // Update ContentDocument (File) } catch(DMLException e){ system.debug('Exception has occurred! ' +e.getMessage()); } List<ContentDocument> DocumentList = new List<ContentDocument>(); Set<Id> documentIds = new Set<Id>(); List<ContentDocumentLink> cdl=[select id,LinkedEntityId,ContentDocumentId from ContentDocumentLink where LinkedEntityId=:recordId]; for(ContentDocumentLink cdLink:cdl){ documentIds.add(cdLink.ContentDocumentId); } DocumentList = [select Id,Title,FileType,ContentSize,Description from ContentDocument where id IN: documentIds]; return DocumentList; // Return list of files on parent record } }
Just copy and paste below code in your org.
Kindly mark it as solved if it solve your query.
Thanks and Regards,
Uttpal Chandra