I am practicing SOSL queries. I tried to find the matching records of given Email ID across all objects and update it to new Email ID using SOSL query.
My Code:
public class Soslxmpl{
public List<List<Sobject>> updateEmail(){
String emailid = '[email protected]';
List<List<SObject>> Sobj = [FIND '[email protected]'
IN email Fields
Returning
Case(CaseNumber,SuppliedEmail),
Candidate__C(Name,Email_Id__c),
Contact(Name),
Lead(Name)];
Case[] cases = (Case[])Sobj[0];
Candidate__C[] cand = (Candidate__C[])Sobj[1];
Contact[] cont = (Contact[])Sobj[2];
Lead[] leads = (Lead[])Sobj[3];
for(Case Casse : Cases)
{
Casse.SuppliedEmail= emailid;
}
for(Candidate__C Candi : cand)
{
Candi.Email_Id__C = emailid;
}
For(Contact con : Cont)
{
con.Email = emailid;
}
return Sobj;
update Sobj;
} }
I don't know how to update generic objects.Please help me to update email with new mail id.