You need to sign in to do that
Don't have an account?
Haseeb Ahmad 9
Salesforce lightning component controller apex test class
Hi Everyone,
Having some issues creating a test class for the controller.
I am have tried many ways but either I am not getting any coverages or getting errors. Would love some helpful insight on how to create a test for this. thank you.
Having some issues creating a test class for the controller.
public without sharing class DeleteFilesCtrl { @AuraEnabled public static List<FilesWrap> getFiles(string objectId){ List<FilesWrap> wrapList = new List<FilesWrap>(); List<ContentDocumentLink> cdList = [SELECT ContentDocument.Title,ContentDocument.FileType,ContentDocument.LastModifiedDate , ContentDocumentId,LinkedEntityId FROM ContentDocumentLink WHERE LinkedEntityId =:objectId]; for(ContentDocumentLink cd : cdList){ if(cd.ContentDocument.FileType != 'SNOTE'){ wrapList.add(new FilesWrap(cd)); } } System.debug('---'+wrapList); return wrapList; } @AuraEnabled public static string deleteFiles(string objectId,string contentDocumentId){ List<ContentDocumentLink> cdlList = [SELECT ContentDocumentId,LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId=:contentDocumentId]; try{ if(cdlList.size() <= 2){ delete [SELECT Id FROM ContentDocument WHERE Id = :contentDocumentId]; }else{ delete [SELECT ContentDocumentId,LinkedEntityId FROM ContentDocumentLink WHERE LinkedEntityId=:objectId AND ContentDocumentId=:contentDocumentId]; } }catch(Exception ex){ return ex.getMessage(); } return 'Success'; } public class FilesWrap{ @AuraEnabled public String title; @AuraEnabled public String fileType; @AuraEnabled public String id; @AuraEnabled public DateTime lastModifiedDate; public FilesWrap(ContentDocumentLink cd){ title = cd.ContentDocument.Title; id = cd.ContentDocumentId; fileType = cd.ContentDocument.FileType; lastModifiedDate= cd.ContentDocument.LastModifiedDate; } } }
I am have tried many ways but either I am not getting any coverages or getting errors. Would love some helpful insight on how to create a test for this. thank you.
Best Answer chosen by Haseeb Ahmad 9
Haseeb Ahmad 9
This is resolve by following test class: