• SFDC Panther 92
  • NEWBIE
  • 25 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies

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
 
I am trying to create a test class for my apex class but i am getting an error.Can anyon please help me with it.

Apex 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();
           //livechat.returnChatTranscriptRecord();
                
        id chatlist =  GlobalWebChatBotServiceClass.returnChatTranscriptRecord(chat.Id);
        

    }
    
}
 

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
 
I am trying to create a test class for my apex class but i am getting an error.Can anyon please help me with it.

Apex 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();
           //livechat.returnChatTranscriptRecord();
                
        id chatlist =  GlobalWebChatBotServiceClass.returnChatTranscriptRecord(chat.Id);
        

    }
    
}