2

I have an standard einstein bot that is calling an apex class. That apex class must accept a list of objects as input, and a string as output (with the value the the one in the first object of the list, in its field answer__c). The class is:

public with sharing class GetKnowledgeAnswer {
    
    @InvocableVariable(label='Input Object List' required=true)
    public List<sObject> knowledgeSearchResults;
    
    @InvocableVariable(label='Output Answer String' required=false)
    public String answer;

    @InvocableMethod(label='Get Knowledge Answer')
    public static List<GetKnowledgeAnswer> getAnswerFromKnowledge(List<GetKnowledgeAnswer> invokers) {
        for (GetKnowledgeAnswer invoker : invokers) {
            if (invoker.knowledgeSearchResults != null && !invoker.knowledgeSearchResults.isEmpty()) {
                Object firstObject = invoker.knowledgeSearchResults[0];
                if (firstObject instanceof Knowledge__kav) {
                    Knowledge__kav knowledgeObj = (Knowledge__kav) firstObject;
                    invoker.answer = knowledgeObj.Answer__c;
                } else {
                    invoker.answer = 'El primer objeto en la lista no es de tipo Knowledge__kav.';
                }
            } else {
                invoker.answer = 'La lista de objetos está vacía o es nula.';
            }
        }
        return invokers;
    }
}

Regarding the bot, that contains all the logic for the business process, the conflicting steps are:

Search knowledge matches:

search knowledge matches

Get answer from first match:

get answer from first match

When previewing the bot, it throws an error when calling the apex class:

Error: Error when invoking /support/conversations/0X909000000xlNF/invocations/0SC09000000xnyMGAQ: [{"actionName":"GetKnowledgeAnswer","errors":[{"statusCode":"REQUIRED_FIELD_MISSING","message":"Missing required input parameter: knowledgeSearc

Why does it say "REQUIRED_FIELD_MISSING"? I'm clearly passing the output from the previous step as input for the apex class. Wondering if previous block gives List<Object> but apex class expects List<sObject>? I'm totally blocked in here, any help would be much appreciated.

1
  • Did you find any solution to this. I am also struggling in a similar use case wherein i want to search from only a subset of knowledge articles . Since Knowledge Object search does not have a OOTB filter, i thought of taking the list returned by the object search and filter it in apex.
    – starhunter
    Apr 10, 2023 at 18:09

1 Answer 1

0

I've got quite same situation with using List variables between Bot and Apex. I decided just to use String variables in Bot and Json.serialize/deserialize combination in Apex.

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 31, 2023 at 15:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .