+ Start a Discussion
SFDC Panther 92SFDC Panther 92 

how to pass wrapper class as parameter in test class


Hi,

I have created a Class for einstein bot and since only one invocable method can be created in a class , i have created a service class and passed the parameter from my controller class. Both the class are working fine and while creating a test class i am able to cover the code coverage of 90% for my service class . But i am facing issue for the controller class.

Controller class
public class GlobalWebChatBotController {
    /* Input Wrapper Class for Values to be passed from Einstein Bot */
    public class ControllerInput {
    @InvocableVariable
    public String fctgBrandName;
    @InvocableVariable
    public String operationTypeString;
    @InvocableVariable
    public String chatTranscriptRecordId;
    @InvocableVariable
    public String enquiry;
    @InvocableVariable
    public String companyName;
    @InvocableVariable
    public LiveChatTranscript chatTranscriptRecord;
    @InvocableVariable
    public String countryName;   
    @InvocableVariable
    public String phoneNumber;
    @InvocableVariable
    public String contactPreference;
    @InvocableVariable
    public String feedbackcomment;
    @InvocableVariable
    public String isfeedback;
    @InvocableVariable
    public String selectedKnowledgeCategory;
    @InvocableVariable
    public String selectedKnowledgeSubCategory;
    @InvocableVariable
    public String selectedTitle;
    @InvocableVariable
    public sObject selectedKnowledgeArticle;
  }
    /* Output Wrapper Class for Values to be passed to Einstein Bot */
    public class ControllerOutput {
    @InvocableVariable
    public LiveChatTranscript chatTranscriptRecord;
    @InvocableVariable
    public String visitorCustomerType;
    @InvocableVariable
    public String supplierPublicDocumentLink;
    @InvocableVariable
    public Case loggedCaseRecord;
    @InvocableVariable
    public Contact linkedContactRecord;
    @InvocableVariable
    public String companyName;
     @InvocableVariable
    public String FirstName;
     @InvocableVariable
    public String LastName;
    @InvocableVariable
    public List<String> knowledgeCategories;
    @InvocableVariable
    public List<String> knowledgeSubCategories;
    @InvocableVariable
    public List<sObject> knowledgeArticle;
  }
    /* Invocable Method of Controller to be called From Einstein Bot*/
    @InvocableMethod(label='')    
    public static List<ControllerOutput> botControllerMethod(list<ControllerInput> controllerInputs){
        GlobalWebChatBotServiceClass serviceClassObject=new GlobalWebChatBotServiceClass();
        ControllerInput inputVariable=controllerInputs[0];
        ControllerOutput outputVariable= new ControllerOutput();
"
"
}

Service class

public without sharing class GlobalWebChatBotServiceClass {
    
    
    
    public  LiveChatTranscript returnChatTranscriptRecord(Id chatTranscriptRecordId) {
          List<LiveChatTranscript> chatTranscriptRecords=[SELECT Id,Visitor_Customer_Type__c,Visitor_Email__c,
                                                        Visitor_First_Name__c,Visitor_Last_Name__c,Visitor_Company__c,ContactId,Location FROM LiveChatTranscript
                                                        Where Id = :chatTranscriptRecordId];
        if(chatTranscriptRecords.size()>0) {
            return chatTranscriptRecords[0];
        } else {
            return null;
        }
    }

Test Class

@isTest
public class GlobalWebChatBotTestClass {        
    @istest
    static void chattranscripttest(){        
        LiveChatTranscript chat = new LiveChatTranscript (Visitor_Customer_Type__c = 'Supplier' , Visitor_Email__c = 'a@a.com' , 
                                         Visitor_First_Name__c = 'testa' ,Visitor_Last_Name__c = 'testb' , livechatvisitorid = '5717Z000001LxeQQAS',
                                          Visitor_Company__c = 'test',Location = 'test');
        insert chat;                
        
         GlobalWebChatBotServiceClass livechat = new GlobalWebChatBotServiceClass();           
        Test.startTest();
        LiveChatTranscript lct= livechat.returnChatTranscriptRecord(chat.Id);
        GlobalWebChatBotController.botControllerMethod( i dont know which parameter i should pass here);
        Test.StopTest();
    }

I dont know how to pass controller input parameter , can anyone help me with it
 
Best Answer chosen by SFDC Panther 92
Yogendra JangidYogendra Jangid
Hi
Try with following 
GlobalWebChatBotController.botControllerMethod(new List<GlobalWebChatBotServiceClass.ControllerInput>{ livechatInput }); pass the wrraper class object here
if this resolves your issue, please can you mark this as best answer.
 

All Answers

Suraj Tripathi 47Suraj Tripathi 47
Hi SFDC Panther 92,
kindly find the solution

Test Class
@isTest
public class GlobalWebChatBotTestClass {        
    @istest
    static void chattranscripttest(){        
        LiveChatTranscript chat = new LiveChatTranscript (Visitor_Customer_Type__c = 'Supplier' , Visitor_Email__c = 'a@a.com' , 
                                         Visitor_First_Name__c = 'testa' ,Visitor_Last_Name__c = 'testb' , livechatvisitorid = '5717Z000001LxeQQAS',
                                          Visitor_Company__c = 'test',Location = 'test');
        insert chat;                
        
    //create wrapper class object here like this.
         GlobalWebChatBotServiceClass.ControllerInput  livechatInput = new GlobalWebChatBotServiceClass.ControllerInput ();  
    //here you have to set value for these fiels 
    livechatInput.fctgBrandName = "";
    livechatInput.operationTypeString= '';
    //set values for all data member of wrapper class.
        
        Test.startTest();
        LiveChatTranscript lct= livechat.returnChatTranscriptRecord(chat.Id);
        GlobalWebChatBotController.botControllerMethod( livechatInput ); pass the wrraper class object here
        Test.StopTest();
    }
If you find your Solution then mark it as the best answer. 

Thanks and Regards
Suraj Tripathi.
 
SFDC Panther 92SFDC Panther 92
Hi Suraj

I am still getting the same error , i.e. Method does not exist or incorrect signature: void botControllerMethod(GlobalWebChatBotController.ControllerInput) from the type GlobalWebChatBotController
Yogendra JangidYogendra Jangid
Hi
Try with following 
GlobalWebChatBotController.botControllerMethod(new List<GlobalWebChatBotServiceClass.ControllerInput>{ livechatInput }); pass the wrraper class object here
if this resolves your issue, please can you mark this as best answer.
 
This was selected as the best answer
SFDC Panther 92SFDC Panther 92
Hi Yogendra

Thanks a lot.. it worked
Yogendra JangidYogendra Jangid
Glad to hear that it worked, please can you mark this as best answer in this case. Many thanks.