0

I have an apex class that returns a list of records/response as an output.

public class KnowledgeArticleLookup {

   @InvocableMethod(label='Get Knowledge Articles' description='Gets knowledge article results')
   public static List<List<Response>> getMyArticles (List<Request> req){
    List<KnowledgeArticleVersion> Articles = new List<KnowledgeArticleVersion>();

    if(req[0].varType1 == 'Global Info'){
      if(req[0].varType2 == 'Location'){
            articles = [SELECT Id,
                              Title 
                             FROM KnowledgeArticleVersion 
                             WHERE PublishStatus='online' 
                             WITH DATA CATEGORY 
                             Global_Knowledge__c AT Location__c];
      }
    }
    List<List<Response>> outputResponse = new List<List<Response>>();
    List<Response> responses = new List<Response>();
    for(KnowledgeArticleVersion kav: articles) {
         Response response = new Response();
         response.articleversionId = kav.Id;
         response.articleTitle = kav.Title;
         responses.add(response);
    }
    outputResponse.add(responses);
   return outputResponse;
  }

  public class Request {
    @InvocableVariable(required=true)
     public String varType1;
    @InvocableVariable(required=true)
     public String varType2;
   }

   public class Response {
      @InvocableVariable
       public String articleversionId;
      @InvocableVariable
       public String articleTitle;
   }
}

when I debug my flow, my apex class returns the result as follow: enter image description here

I was wondering how I can assign my articleversionId to a flow collection variable, knowing that my flow apex action doesn't give me the possibility to store my output variable (screenshot below). enter image description here

8
  • Under advanced, if you check the "Manually assign variables" checkbox, it should allow you to assign. Aug 9 '21 at 10:30
  • Hi @Aditya, Thanks for your response. it does but i can not assign a collection variable
    – user52619
    Aug 9 '21 at 10:34
  • May be you should try returning a list from Apex. global List<String> articleVersionId Aug 9 '21 at 10:47
  • I do return a List<List<Response>>
    – user52619
    Aug 9 '21 at 10:51
  • Try adding the code to the question itself, and may be elaborate a bit on current behavior and expected behavior. Aug 9 '21 at 10:53
1

You need to move the Response inner class to a dedicated class so that it can be picked up as an Apex-Defined type by a flow.

global class Response {
    @AuraEnabled @InvocableVariable
    global String articleversionId;

    @AuraEnabled @InvocableVariable
    global String articleTitle;
}

You can then define a Resource with this new Apex Type.

enter image description here

and finally, you can assign the response from your invocable action to this resource.

enter image description here

0

The basic problem is that you're returning a single string: public String varType1;

...and you can't automatically assign a single string to a collection of strings.

As Aditya proposes in the comments, you can change the output type to return a collection:

   public class Response {
      @InvocableVariable
       public List<String> articleversionIdList;
      @InvocableVariable
       public String articleTitle;
   }

then, in your code, initialize your list and push your actual id into it:

List<String> articleversionIdList = new List<String>();
articleversionIdList.add(articleversionId);

Now your id is loaded into a collection and you can assign it to another collection variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.