• lindaxen
  • NEWBIE
  • 0 Points
  • Member since 2023
  • SEO Executive
  • digitalmarketing

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
public class CreateCaseUsingFlow {
    @InvocableMethod(label = 'Attach File')
    public static List<FlowOutput> createFile(List<FlowInput> list_FlowInput) {
        System.debug('list_FlowInput[0].attachment ==>' +list_FlowInput[0].attachment);
        System.debug('list_FlowInput[0].caseId ==>' +list_FlowInput[0].caseId);
        System.debug('list_FlowInput[0].attachmentName ==>' +list_FlowInput[0].attachmentName);

        
        Boolean isFileSuccessfullyCreate = false;

            String attachment = list_FlowInput[0].attachment;
       	    String attachmentName = list_FlowInput[0].attachmentName;
           
            ContentVersion conVer = new ContentVersion();
            conVer.ContentLocation = 'S';
            conVer.PathOnClient =attachmentName; 
            conVer.Title = attachmentName;
            conVer.VersionData = EncodingUtil.base64Decode(attachment);
            insert conVer;
            
            Id conDocId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:conVer.Id].ContentDocumentId;
            
            ContentDocumentLink conDocLink = New ContentDocumentLink();
            conDocLink.LinkedEntityId = list_FlowInput[0].caseId; 
            conDocLink.ContentDocumentId = conDocId;  
            conDocLink.shareType = 'V';
            insert conDocLink;
            isFileSuccessfullyCreate = true;
                       
        List<FlowOutput> list_FlowOutput = new List<FlowOutput>();
        FlowOutput obj_FlowOutput = new FlowOutput();
        obj_FlowOutput.isFileSuccessfullyCreate = isFileSuccessfullyCreate;
        list_FlowOutput.add(obj_FlowOutput);
        
        return list_FlowOutput;
    }
    
    public class FlowInput {
        @InvocableVariable(label=' Case Id' required='true')
        public String caseId;
        @InvocableVariable(label='ContentVersion attachment' required='true')
        public String attachment;
        @InvocableVariable(label='ContentVersion attachmentName' required='true')
        public String attachmentName;
    }
    
    public class FlowOutput {
        @InvocableVariable(label='isFileSuccessfullyCreate')
        public Boolean isFileSuccessfullyCreate;
    }
}

how do I write the test class for this code please suggest
thanks