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
debprakash shawdebprakash shaw 

Help with Test Class for Invocable Apex Action called from FlowInput

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 
debprakash shawdebprakash shaw
I will try like 
@isTest
public class CreateCaseUsingFlowTest {
    @TestSetup
    static void setupData(){
        Case caseObj=new Case();
        caseObj.status='closed';
        caseObj.Priority='Medium';
        caseObj.Origin='Eb Portal';
        caseObj.Reason='Operations – General Enquiry';
        caseObj.Subject='Case from portal';
        caseObj.Type='Operations';
        caseObj.Application_Name__c='EB Portal';
        caseObj.Description='test';
        caseObj.CurrencyIsoCode='GBP';
        insert caseObj;

        CreateCaseUsingFlow.FlowInputs firstInput = new CreateCaseUsingFlow.FlowInputs(); //(get error here)
        firstInput.caseId=caseObj.Id;
        firstInput.attachment='dGhpcyBpcyBkZW1v';
        firstInput.attachmentName='text';

        ContentVersion contentVersion = new ContentVersion(
            Title = 'attachment',
            PathOnClient = 'attachment',
            VersionData =EncodingUtil.base64Decode('attachment'),
            IsMajorVersion = true
        );
        insert contentVersion;    
        List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];
        
        //create ContentDocumentLink  record 
        ContentDocumentLink cdl = New ContentDocumentLink();
        cdl.LinkedEntityId = caseObj.id;
        cdl.ContentDocumentId = documents[0].Id;
        cdl.shareType = 'V';
        insert cdl;
        
        
        Test.startTest();
        CreateCaseUsingFlow.createFile(new List<CreateCaseUsingFlow.FlowInputs>{firstInput});
        Test.stopTest();
    }
}

but get an error like

//Variable does not exist: firstInput
//Invalid type: CreateCaseUsingFlow.FlowInputs
//Variable does not exist: firstInput
//Invalid type: CreateCaseUsingFlow.FlowInputs
//Variable does not exist: firstInput
lindaxenlindaxen
Codes can be digital or physical cards that you purchase from Microsoft or a trusted retailer.
redeem.microsoft.com (https://microsoftcomredeem.com)