function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rahul AlladaRahul Allada 

How to write a test class for the below method?

public class quoteFlowClass {
   @InvocableMethod
    Public static void attachPDF(List<string> quoteId){
        Blob pdfBlob;
        PageReference pdfPage = Page.QuoteGeneration;
        pdfPage.getParameters().put('id',quoteId[0]);
        pdfBlob = pdfPage.getContentAsPDF();
        id quoteIdd = quoteId[0];
        List<ContentDocumentLink> quotList = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId =: quoteIdd];
        integer m = quotList.isEmpty() ? 0 : quotList.size();
        m=m+1;
        Quote__c pdfParent = [SELECT Name FROM Quote__c WHERE Id = :quoteId[0]];
        
        ContentVersion cv = new ContentVersion(
            Title=pdfParent.Name+'-V'+m+'.pdf', 
            PathOnClient=pdfParent.Name+'-V'+m+'.pdf', 
            VersionData=pdfBlob
        );
        insert cv;
        
        cv = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = :cv.Id];
        ContentDocumentLink cdl = new ContentDocumentLink(
            ContentDocumentId = cv.ContentDocumentId,
            LinkedEntityId = pdfParent.Id,
            ShareType = 'I', // Inferred Share
            Visibility = 'AllUsers'
        );
        insert cdl;
    }

  }
    
I tried doing my best, but not able to cover. This class is invoked from flows as a quick action