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

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
Hi  All

I am having a scenario where through a batch i am creating new survey forms in the application and have to copy response from previous survey form to new survey form.
Survey question and Survey answer are 2 different object and survey answer is using survey question ( question Id) as lookup.
Now , When I am creating new survey through batch , since there are multiple survey and each survey has multiple answers records , i am not able to understand how to copy the response from previous survey to new survey.

We will get survey answer record through survey Id and question id , so I want to know how can I keep these 2 field as a Key in Map.

Below is my code where I copy the response from one survey to another but the issue is it work only for 1 survey , not for List of Survey.

List<Survey__answer__C> OldSurvey = [Select questionid , answer__c from survey__c  where Survey__c = :oldsurveyId];
List<Survey__answer__C> NewSurvey = [Select questionid , answer__c from survey__c  where Survey__c = :newsurveyId];
Map<Id,String> mapofsurvey = new Map Map<Id,String>;
List<Survey__answer__C> SurveyListtoUpdate = new List<Survey__answer__C>;

for(Survey__answer__C oldsurveyAnswer :OldSurvey)
{
    mapofsurvey.put(OldSurvey.questionid ,OldSurvey.answer__c);
}

for(Survey__answer__C newsurveyAnswer :NewSurvey)
{
    newsurveyAnswer.answer__c = mapofsurvey.get(newsurveyAnswer.questionid);
    SurveyListtoUpdate.add(newsurveyAnswer);
}

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);
        

    }
    
}