+ Start a Discussion
vijendahr kvijendahr k 

SOSL dynamic query issue

Due to some email field in my org, i cant query use email fields in soql query on ontact object. hence i developed below logic,
conset i am using it just for sample puruose, in my code source of email address are different . i collectd in set.

list<contact> conset=[select email from contact where email != null];
list<contact> conlist= new list<contact>();
set<string> emailids= new set<string>();
for(contact c:conset)
{
    if(c.email!='' || c.email != null )
    {
         emailids.add(c.email);
    
    }
 }

string querystring='';
string querystringACt='';
boolean Soslflg=false;
for(string str:emailids)
{
    querystring+=str+ ' OR ';
    if(querystring.length() >300)
    {
        system.debug('querystring==>'+querystring);
       querystringACt=querystring;
        querystring='';
        Soslflg=true;
    }
    if(Soslflg)
    {
        system.debug('inside soslflag'+querystringACt );
        List<List<SObject> > contacts = [FIND :querystringACt IN ALL FIELDS RETURNING Contact (id,name,email)];
       system.debug('sosl query'+contacts );
   conlist=contacts[0];
        system.debug('conlist== '+conlist);
       querystringACt ='';
        Soslflg=false;
 }
}
in the qbove query List<List<SObject> > contacts = [FIND :querystringACt IN ALL FIELDS RETURNING Contact (id,name,email)]; is always cming as blank. could you tell me what is the reason.

i tried below snippet . its working but inside loop its not working :--
string querystringACt='soslflagnullrose@edge.com OR sean@edge.com OR jrogers@burlington.com OR pat@pyramid.net OR a_young@dickenson.com OR barr_tim@grandhotels.com OR bond_john@grandhotels.com OR spavlova@uog.com OR lboyle@uog.com OR b.levy@expressl&t.net OR j.davis@expressl&t.net OR jane_gray@uoa.edu OR asong@uog.com OR ajames@uog.com';
List<List<SObject> > contacts = [FIND :querystringACt IN ALL FIELDS RETURNING Contact (id,name,email)];
system.debug('conlist== '+contacts[0]);


can any please help me fix it up


Thanks Advance