

public class searchToolInvocable {
@invocablemethod
public static List<Response> execute(List<Request> flowRequest){
System.debug(flowRequest);
System.debug(flowRequest[0]);
String searchTerm = flowRequest[0].searchTerm;
List<List<Sobject>> searchList = [FIND :searchTerm IN ALL FIELDS RETURNING
Account(Id,Name,Phone,Industry,AnnualRevenue),
Contact(Id,Name,Phone,Email,Title),
Lead(Id,Name,Company, Email,Phone),
Case(Id,Subject),
Opportunity(Id,Name,Amount,CloseDate,StageName)];
Response res = New Response();
res.Accounts=searchList[0];
res.Contacts=searchList[1];
res.Leads=searchList[2];
res.Cases=searchList[3];
res.Opportunities=searchList[4];
List<Response> flowResponse = New List<Response>();
flowResponse.add(res);
return flowResponse;
}
public class Request{
@invocableVariable(label='Search Term' description='Search from your CRM' )
public String searchTerm;
}
public class Response {
@invocableVariable(label='Accounts' description='Accounts' )
public List<Account> Accounts;
@invocableVariable(label='Contacts' description='Contacts' )
public List<Contact> Contacts;
@invocableVariable(label='Leads' description='Accounts' )
public List<Lead> Leads;
@invocableVariable(label='Opportunities' description='Accounts' )
public List<Opportunity> Opportunities;
@invocableVariable(label='Cases' description='Cases' )
public List<Case> Cases;
}
}




