You need to sign in to do that
Don't have an account?

dynamic SOSL in Apex Class
Hi,
I am trying to use dynamic search string in Apex class and while executing below code, I don't see the log window. It executes without error but no log window comes up. What am I missing?
Class:
Public Class ContactAndLeadSearch{
Public static List<List<sObject>> searchContactsAndLeads(String searchword){
String searchQuery = 'FIND \'' + searchword + '\' IN NAME FIELDS RETURNING Lead(Name where FirstName = \'' + searchword + '\' or LastName = \'' + searchword + '\'),Contact(FirstName,LastName where FirstName = \'' + searchword + '\' or LastName = \'' + searchword + '\')';
List<List<sObject>> searchConLead = search.query(searchQuery);
return searchConLead;
}
}
In Debug Annonymous window:
List<List<sObject>> searchContactLead = ContactAndLeadSearch.searchContactsAndLeads('Smith');
List<Lead> leadList = New List<Lead>();
List<Contact> contList = New List<Contact>();
leadList = ((List<Lead>)searchContactLead[0]);
contList = ((List<Contact>)searchContactLead[1]);
for(Lead a:leadList){
System.debug('Found following Leads ' + a.Name);
}
for(Contact cts:contList){
System.debug('Found following Contacts ' + cts.FirstName + '' + cts.LastName);
}
I am trying to use dynamic search string in Apex class and while executing below code, I don't see the log window. It executes without error but no log window comes up. What am I missing?
Class:
Public Class ContactAndLeadSearch{
Public static List<List<sObject>> searchContactsAndLeads(String searchword){
String searchQuery = 'FIND \'' + searchword + '\' IN NAME FIELDS RETURNING Lead(Name where FirstName = \'' + searchword + '\' or LastName = \'' + searchword + '\'),Contact(FirstName,LastName where FirstName = \'' + searchword + '\' or LastName = \'' + searchword + '\')';
List<List<sObject>> searchConLead = search.query(searchQuery);
return searchConLead;
}
}
In Debug Annonymous window:
List<List<sObject>> searchContactLead = ContactAndLeadSearch.searchContactsAndLeads('Smith');
List<Lead> leadList = New List<Lead>();
List<Contact> contList = New List<Contact>();
leadList = ((List<Lead>)searchContactLead[0]);
contList = ((List<Contact>)searchContactLead[1]);
for(Lead a:leadList){
System.debug('Found following Leads ' + a.Name);
}
for(Contact cts:contList){
System.debug('Found following Contacts ' + cts.FirstName + '' + cts.LastName);
}
Please try below class:-
NOTE:- if you want to search same keyword in mutliple field then dnt add where you can try IN ALL FIELDS.
Execute below code in In Debug Annonymous window
You can also try workbanch.
https://workbench.developerforce.com/login.php
To Execute Annonymous code like below :-
Above code is working fine for me.
Please mark this as Best Answer if this will help you.
Thanks
Amit Chaudhary
All Answers
Try this chrome plugin for checking log file easily - https://chrome.google.com/webstore/detail/salesforce-developer-tool/fiaakhiohminpblhmlihfcdhclmphjcd
Thanks,
Karanraj (http://www.karanrajs.com)
Please try below class:-
NOTE:- if you want to search same keyword in mutliple field then dnt add where you can try IN ALL FIELDS.
Execute below code in In Debug Annonymous window
You can also try workbanch.
https://workbench.developerforce.com/login.php
To Execute Annonymous code like below :-
Above code is working fine for me.
Please mark this as Best Answer if this will help you.
Thanks
Amit Chaudhary
Karan: I tried your suggestion of adding my name in Setup>Log>Monitor Log and Debug window opened this time. Also Salesforce Developer Tool suite is awesome!! The debug window showed the right set of records :)
Amit: Thank you and will try in ALL fields if I have to search for multiple fields. Will check out the workbench as well.
Regards,
Unna