function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Arthur Almeida 12Arthur Almeida 12 

Different results executing in Anonymous Window and in Einstein Bot

I have this class:
public class Class {    
    public class HandleInput {        
        @InvocableVariable(required=true)        
        public String idAsset;    
    }        
    public class HandleOutput {        
        @InvocableVariable(required=true)        
        public String status;    
    }

    @InvocableMethod    
    public static List<HandleOutput> find(List<HandleInput> inputParameters){        
        String idAsset = inputParameters.get(0).idAsset;                
        String status = [SELECT Status FROM Asset WHERE id =: idAsset];

        List<HandleOutPut> outPuts = new List<HandleOutput>();        

        HandleOutput outPut = new HandleOutput();        
        outPut.statusPreAutorizacao = status;        
        outPuts.add(outPut);                
        return outPuts;    
    }
}

When I execute this class in the anonymous window, the result is Success, but when the Einstein Bot executes the class, it gives an error:
System.QueryException: List has no rows for assignment to SObject

When I execute in the anonymous window, I execute this script:
Class.HandleInput handleInput = new Class.HandleInput();
handleInput.idAsset = X;

List<Class.HandleInput> inputParameters = new List<Class.HandleInput>();
inputParameters.add(handleInput);

List<Class.HandleOutput> outputs = Class.find(inputParameters);
System.debug(outputs.get(0).status);

Why the result is different from executing in anonymous and in Einstein Bot?
Best Answer chosen by Arthur Almeida 12
Arthur Almeida 12Arthur Almeida 12

I solved my problem add the "without sharing" keyword to my class.