You need to sign in to do that
Don't have an account?
Michael M
Test class for invocable class for bot
Hello, I have the following apex class that I want to invoke from my einstein bot. Can someone help me with writing the test class for this code?
public with sharing class BotUrlClass {
public class TranscriptInput {
@InvocableVariable(required=true)
public ID routableID;
}
public class VisitorUrlOutput {
@InvocableVariable(required=true)
public String url;
}
@InvocableMethod(label='Get User Name')
public static List<VisitorUrlOutput> getUserName(List<TranscriptInput> transcripts) {
List<VisitorUrlOutput> urls = new List<VisitorUrlOutput>();
for (TranscriptInput transcript : transcripts) {
// Query for the transcript record based on the ID
LiveChatTranscript transcriptRecord = [SELECT Name, URL__c
FROM LiveChatTranscript
WHERE Id = :transcript.routableID
LIMIT 1];
// Store the first name in an output variable
VisitorUrlOutput urlData = new VisitorUrlOutput();
urlData.url = transcriptRecord.URL__c;
// Add the name to the list of outputs
urls.add(urlData);
}
return urls;
}
}
public with sharing class BotUrlClass {
public class TranscriptInput {
@InvocableVariable(required=true)
public ID routableID;
}
public class VisitorUrlOutput {
@InvocableVariable(required=true)
public String url;
}
@InvocableMethod(label='Get User Name')
public static List<VisitorUrlOutput> getUserName(List<TranscriptInput> transcripts) {
List<VisitorUrlOutput> urls = new List<VisitorUrlOutput>();
for (TranscriptInput transcript : transcripts) {
// Query for the transcript record based on the ID
LiveChatTranscript transcriptRecord = [SELECT Name, URL__c
FROM LiveChatTranscript
WHERE Id = :transcript.routableID
LIMIT 1];
// Store the first name in an output variable
VisitorUrlOutput urlData = new VisitorUrlOutput();
urlData.url = transcriptRecord.URL__c;
// Add the name to the list of outputs
urls.add(urlData);
}
return urls;
}
}
Same with other variables
All Answers
Try this once.
For refernce,
http://amitsalesforce.blogspot.com/2018/07/einstein-bots-with-apex-class-how-to.html
Thanks.
The invocable method is just a static method. You can simply call it on your test to verify that it works as intended.
Let me know if it gives you any coverage
Regards,
Anudeep
Thank you very much for sending. I am trying to save this class but it is giving me errors, saying "Invalid type: Transcriptinput'. Here are the "Problems" it is showing:
Same with other variables
List<BotUrlClass.TranscriptInput>
See this example
Let me know if this helps, if it does, please close the query by marking it as solved. It may help others in the community. Thank You!
Class.BotUrlTESTClass.doTest: line 20, column 1
Here is what the test class is looking like:
@isTest
public class BotUrlTESTClass {
private static testMethod void doTest() {
//LiveChatTranscript lct = new LiveChatTranscript();
// insert lct;
List<BotUrlClass.Transcriptinput> inputList = new List<BotUrlClass.TranscriptInput>();
Test.startTest();
BotUrlClass.TranscriptInput input = new BotUrlClass.TranscriptInput();
input.routableID = '5703l000003EF3NAAW';
inputList.add(input);
BotUrlClass.VisitorUrlOutput output = new BotUrlClass.VisitorUrlOutput();
output.url = 'https://www.google.com';
BotUrlClass.getUrlName(inputList);
Test.stopTest();
}
}