Is there a way to convert Apex Select Statement to String

311 Views Asked by At

I have all the permission sets updated correctly as I i can hardcode a string 'Test' where the select statement is, but when i put in the select statement, My chat bot immediately closes. Could someone take a quick look? I am trying to test that I can take an email address, search the contact object and return the appDecision (Custom Field)

public with Sharing class GetAdmissionStatus {
public class DecisionOutput {  
  
    @InvocableVariable( required=true )  
    public String aDecision;  
}  
  
public class DecisionInput {  
  
    @InvocableVariable( required=true )  
    public String applyEmail;  
      
}  

@InvocableMethod(label='Get Admission Status')  
public static List < DecisionOutput > GetAdmissionStatus( List < DecisionInput > listDecisionInputs ) {  
  
    List < DecisionOutput > objOutputs = new List < DecisionOutput >();  
    DecisionOutput objOutput = new DecisionOutput();  
    Set < String > strapplyEmails = new Set < String >();  
    for ( DecisionInput objDecisionInput : listDecisionInputs )  
        strapplyEmails.add( objDecisionInput.applyEmail );  
    objOutput.aDecision = [ SELECT AppDecision__c FROM Contact WHERE Email IN: strapplyEmails LIMIT 1].AppDecision__c;  
    objOutputs.add( objOutput );   
    return objOutputs;  
  
}  

}

1

There are 1 best solutions below

0
On

Question is unclear. You have a query in [brackets] and you want to see a text version of it? Try with

String q = Database.getQueryLocator([SELECT Id FROM Account LIMIT 5]).getQuery();
System.debug(q);

If you want to cast query results to string this might help

String x = JSON.serializePretty([SELECT Id FROM Account LIMIT 5]);
// you can do JSON.serialize() too
System.debug(x);

If the bot closes there's high chance some exception is thrown. Try to play with the bot with DeveloperConsole open, see if it throws anything.

And did you give the "bot user" permission to use this apex class, contact object and the fields? Search in https://developer.salesforce.com/docs/atlas.en-us.bot_cookbook.meta/bot_cookbook/bot_cookbook_call_apex_action.htm for "permission set"