You need to sign in to do that
Don't have an account?
Arthur Almeida 12
Field with @InvocableVariable(required=false) does not is ignored by einstein bot
I have an apex class like this:
In Einstein Bot, when I put action apex, calling this class, the output shows me name and value
Well, from the moment I commented line 25, and annotated the field as required=false (line 09), the Einstein bot must ignore the name field, and must KEEP the bot's name variable with the value it had before of this apex call, correct?
but this is not happening... the bot is not ignoring this field, it is setting NULL for the name field... I would like the field to keep the value it had before
01 public class Example { 02 03 public class HandleInput { 04 @InvocableVariable(required=true) 05 public String id; 06 } 07 08 public class HandleOutput { 09 @InvocableVariable(required=false) 10 public String name; 11 12 @InvocableVariable(required=true) 13 14 public double value; 15 } 16 17 @InvocableMethod 18 public static List<HandleOutput> function(List<HandleInput> inputParameters){ 19 String id = inputParameters.get(0).id; 20 21 ResponseIntegration response = new SomeIntegration().call(id); 22 23 List<HandleOutPut> outPuts = new List<HandleOutput>(); 24 HandleOutput outPut = new HandleOutput(); 25 //outPut.name = response.getName(); 26 outPut.confidence = response.getValue(); 27 28 outPuts.add(outPut); 29 return outPuts; 30 } 31 }
In Einstein Bot, when I put action apex, calling this class, the output shows me name and value
Well, from the moment I commented line 25, and annotated the field as required=false (line 09), the Einstein bot must ignore the name field, and must KEEP the bot's name variable with the value it had before of this apex call, correct?
but this is not happening... the bot is not ignoring this field, it is setting NULL for the name field... I would like the field to keep the value it had before
From the code you've provided, it seems that when the name field is commented out on line 25, the value of the name field is not being set to anything. If the name field is annotated as required=false (line 09), it means that the field is optional and can be left empty.
In this case, the Einstein Bot is likely setting the name field to null because it is not receiving a value for that field from the Apex class. To keep the value of the name field as it was before the Apex call, you can set the name field to its previous value before the Apex call inside the method
public class Example {
public class HandleInput {
@InvocableVariable(required=true)
public String id;
}
public class HandleOutput {
@InvocableVariable(required=false)
public String name;
@InvocableVariable(required=true)
public double value;
}
@InvocableMethod
public static List<HandleOutput> function(List<HandleInput> inputParameters){
String id = inputParameters.get(0).id;
ResponseIntegration response = new SomeIntegration().call(id);
List<HandleOutPut> outPuts = new List<HandleOutput>();
HandleOutput outPut = new HandleOutput();
//keep the value of name as it was before the Apex call
outPut.name = BotContext.current().getVariable('name').getValue();
outPut.value = response.getValue();
outPuts.add(outPut);
return outPuts;
}
}
This will set the name field to the value it had before the Apex call, by getting the value of the name variable from the BotContext.
Please note that this is a simplified example and you will need to adjust it to match your specific use case.
Also, BotContext is used to get values from the current context of the bot flow, so you have to make sure this is being used in the correct context