You need to sign in to do that
Don't have an account?
Raffus
How to write a test method for related objects with wrapper class in it.
I am not understanding what and how to put data for the below method
Please help...
@AuraEnabled public static string getCasesData(String caseId) { try { String query = 'SELECT Id,(SELECT Id, ContentDocumentId FROM ContentDocumentLinks), CaseNumber,Issue_category__c, Issue_Sub_Category__c, rand_App_Customer__r.Party_Id__c,rand_App_Customer__r.Customer_Mobile__c, Current_Location__Latitude__s, Current_Location__Longitude__s, LocationName__c, Owner.Name, Description,CreatedDate FROM Case WHERE Id =:caseId'; query += ' ORDER BY CreatedDate DESC LIMIT 1'; List<Case> cases = Database.query(query); CaseInfoWrapper caseInfo = new CaseInfoWrapper(); set<Id> contentDocId = new set<Id>(); for (Case caseRecord : cases) { caseInfo.description = caseRecord.Description; caseInfo.longitude = caseRecord.Current_Location__Latitude__s; caseInfo.latitude = caseRecord.Current_Location__Longitude__s; caseInfo.locationName = caseRecord.LocationName__c; caseInfo.category = caseRecord.Issue_category__c; caseInfo.subCategory = caseRecord.Issue_Sub_Category__c; caseInfo.partyId = caseRecord.rand_App_Customer__r.Party_Id__c; caseInfo.mobile = caseRecord.rand_App_Customer__r.Customer_Mobile__c; if (caseRecord.ContentDocumentLinks.size() > 0) { for (ContentDocumentLink cdl : caseRecord.ContentDocumentLinks) { contentDocId.add(cdl.ContentDocumentId); } } } list<id> contectVersionID = new list<id>(); map<Id, ContentDistribution> contectDMap = new map<Id, ContentDistribution>(); for (ContentDistribution conDistribution : [SELECT Id, ContentDocumentId, ContentDownloadUrl FROM ContentDistribution WHERE ContentDocumentId IN:contentDocId ORDER BY CreatedDate ASC]) { contectVersionID.add(conDistribution.ContentDocumentId); contectDMap.put(conDistribution.ContentDocumentId, conDistribution); } list<FileInfoWrapper> fileInfo = new list<FileInfoWrapper>(); caseInfo.contentDocumentIds = contectVersionID; for (ContentVersion cv : [SELECT Id, ContentDocumentId, FileExtension, FileType, PathOnClient, VersionData FROM ContentVersion WHERE ContentDocumentId IN:contectVersionID ORDER BY CreatedDate ASC]) { FileInfoWrapper fileData = new FileInfoWrapper(); fileData.base64Data = String.valueOf(cv.VersionData); fileData.contentVersionId = cv.Id; fileData.fileName = cv.PathOnClient; if (contectDMap.containsKey(cv.ContentDocumentId)) { fileData.publicUrl = contectDMap.get(cv.ContentDocumentId).ContentDownloadUrl; fileData.contentDistributionId = contectDMap.get(cv.ContentDocumentId).Id; } fileInfo.add(fileData); } caseInfo.files = fileInfo; System.debug('caseInfo ##' + JSON.serialize(caseInfo)); return JSON.serialize(caseInfo); } catch (Exception e) { throw new AuraHandledException(e.getMessage()); } }So far I have written below myself as per my understanding but it is not giving coverage after "for (Case case record : cases)".
@IsTest public static void getCasesDataTest(){ Case caseInfo = new Case(); caseInfo.description = 'test'; caseInfo.RecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get('rand_App').getRecordTypeId(); insert caseInfo; ContentVersion contentVersion = new ContentVersion( Title = 'Penguins', PathOnClient = 'Penguins.jpg', VersionData = Blob.valueOf('Test Content'), IsMajorVersion = true ); insert contentVersion; List<ContentDocument> documents = [ SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument ]; //create ContentDocumentLink record ContentDocumentLink cdl = New ContentDocumentLink(); cdl.LinkedEntityId = caseInfo.id; cdl.ContentDocumentId = documents[0].Id; cdl.shareType = 'V'; insert cdl; randAppController.CaseInfoWrapper wrapper= new randAppController.CaseInfoWrapper(); wrapper.category = 'Emaar Gift Card'; wrapper.subCategory = 'EGC - Card Error/Machine Network Failure'; wrapper.partyId = '1234'; wrapper.mobile = '7894561230'; randAppController.getCasesData('5003M038208iGzOLOU'); }
Please help...
try with below code.
If this helps, Please mark it as best answer.
Thanks!!