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
Anand TripathiSBIAnand TripathiSBI 

Write a SOSL to get contact(Name), Lead(FirstName, Lastname) from Email Fields where value is 'abc@gmail.com'

Abdul KhatriAbdul Khatri
Hi Anand,

I hope this will help you
 
List<Lead> leads = new List<Lead>();
List<Contact> contacts = new List<Contact>();
List<List<SObject>> searchList = [FIND 'abc@gmail.com'
									IN Email FIELDS
									RETURNING Lead(FirstName, LastName), Contact(Name)];
for(List<SObject> sobjList: searchList)
{
    if(sobjList.get(0).getSObjectType() == Schema.Lead.getSObjectType())
        leads = sobjList;

	if(sobjList.get(0).getSObjectType() == Schema.Contact.getSObjectType())    
    	contacts = sobjList;
}
system.debug(leads); 
if(!leads.isEmpty())
{
    //Your Code Here
}
system.debug(contacts);
if(!contacts.isEmpty())
{
    //Your Code Here
}

 
Prasanthi_s1505Prasanthi_s1505
Hi Anand,

Here is the SOSL for above requirement

FIND {abc@gmail.com} IN EMAIL FIELDS RETURNING Lead(FirstName, LastName), Contact(Name)

Thank You,
Prasanthi
Anand TripathiSBIAnand TripathiSBI
Thanks. It worked
Abdul KhatriAbdul Khatri
Hi Anand,

I would like to request selecting one best answer so this question shows up as resolved. Thanks.