When the user enters his name from third party application, The user needs to get all the records(Account(name,Phone,email),Contact(firstname,Lastname),Lead(email,mobile number)) matching the text entered by him.

I have used sosl for this purpose.I am able to get name of all accounts,contacts,leads.

I need to show the respective fields(Account(name,Phone,email),Contact(firstname,Lastname),Lead(email,mobile number)) of different objects.

Here follows my Webservice code:

global class exposewsdl{
global class requestKT{
    webservice string inputName;

global class responseOfWs{
    webservice String [] accounts = new List<String>();
    webservice String [] contacts = new List<String>();
    webservice String [] leads = new List<String>();
    webservice string errorFound;
webservice static responseOfWs getCaseDetailsFromcsNum(requestKT csNum){
        List<Lead> leadList =New List<Lead>();
         List<contact> conList= New List<contact>();
         List<account> accList=New List<account>();

         String searchStr1 = '*'+csNum.inputName+'*';
         String searchQuery = 'FIND \'' +searchStr1  + '\' IN ALL FIELDS RETURNING  Account (Name),Contact(name),Lead(name)';
        List<List <sObject>> searchList = search.query(searchQuery);
        accList = ((List<Account>)searchList[0]);
        conList  = ((List<contact>)searchList[1]);
        leadList = ((List<Lead>)searchList[2]);
        responseOfWs res = new responseOfWs();
        for (Integer i = 0; i<accList.size(); i++) {
        for (Integer i = 0; i < conList.size(); i++) {
        for (Integer i = 0; i < leadList.size(); i++) {
        return res;
    }catch(Exception e){
        responseOfWs res = new responseOfWs();
        res.errorFound = e.getMessage();
        return res;


Please me to show these field values also. Thanks

  • Is pojo class or inner class is required for this purpose.
    – Sathish
    Jul 20 '16 at 11:52

Your query should read like this:

String searchQuery = 'FIND \'' +searchStr1  + '\' IN ALL FIELDS RETURNING  Account 

You'll then need to make the appropriate adjustments in your code when you iterate on what's returned for each object to pull out each of the fields for each object recordId.

  • Yes, I queried these values. How to push the fields of each object to response. Can u please help me. Is pojo class or inner class is required.....
    – Sathish
    Jul 21 '16 at 4:31
  • You're going to need 1 or more inner classes to return this. You don't say how the return request is defined. But, each list will need a wrapper to combine the results of each record, plus I'd expect you to need a wrapper for the combined lists from each object as well. You're also going to need a method for handling return of errors in the body. This is too much to expect in a single answer. Try doing this first for a single object.
    – crmprogdev
    Jul 21 '16 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.