• Vivek Garg 10
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
How to cover a for loop in this below test method
@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());
        }
    }
I have written the below test class
@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.getCasesData(caseInfo.id);

    }
But not covering the for loop that is
 
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);
            }

 
  • September 07, 2022
  • Like
  • 0
Hi,

I want to do salesforce certification Dev 401 and DEV 501. We are partners of Salesforce, so can anybody tell me the exact price of the certification ?

Any pointers on these is highly appreciated.

Thank You,
Yash