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
GMASJGMASJ 

SOQL string search is not returning values

Hi, 

 I am trying to search based on case subject 
 
 Example if different case have subject line as below 
   1. FW: Case for Testing
   2. RW: Case for Testing
   3.  Case for Testing

I was all the above subject line return when I try to update " FW: Case for Testing" 

In below code FW and RW start is getting return not the  with out FW or RW. 
String FWSubject;
  String RWSubject;
  String CaseSubject;
  list<case> cselst = new list<case>();

    for (Case c : [select id,casenumber,subject,ownerid,owner.name from case where id = '5002D000004JCQr']) {
       system.debug('Case Number :' + c.casenumber); 
       system.debug('Case Subject : ' + c.subject);
       system.debug('Case Subject length : ' + c.subject.length());
       system.debug('Case Owner Name : ' + c.owner.name);
       
       CaseSubject = c.subject;
       
       //Search for FW and RW key word were length of the subject is more than 18
        //if(c.subject != null && c.subject.length() > 18){
            if(c.subject.Contains('FW:')){
              FWSubject = c.subject.replaceAll('FW:','');
              System.debug('FQ Trim String :' + FWSubject);     
         }  
    
        if(c.subject.Contains('RW:')){ 
         RWSubject = c.subject.replaceAll('RW:','');
         System.debug('RW Trim String :' + RWSubject);   
        // }     
       }  
     }
     
   system.debug('FWSubject :' + FWSubject);
   system.debug('RWSubject :' + RWSubject);

   //Map<Id, case> c = new Map<Id, case>([select id, casenumber,subject,createddate,ownerid,owner.name from case where CreatedDate = this_year and subject like :('%' + CaseSubject + '%') order by createddate asc limit 10]);
     
   //Search for same case based on subject within 10days. 
   list<case> ctendays = [select id, casenumber,subject,createddate,ownerid,owner.name from case where CreatedDate = this_year and  ( subject like :('%' + CaseSubject + '%') or subject like :('%' + FWSubject + '%') or subject like :('%' + RWSubject + '%') ) order by createddate asc limit 100];
    
   for(case ctndays : ctendays){
      system.debug('Existing Cases :'  + ctndays.casenumber + ' ' + ctndays.subject + ' ' + ctndays.createddate + ' ' + ctndays.owner.name);      
      system.debug('Latest Case Owner ' + ctendays[0].owner.name); 
       
      ctndays.ownerid = ctendays[0].ownerid;
      ctndays.Duplicate_With__c = ctendays[0].casenumber;
       cselst.add(ctndays);
      }  
   
  //if(cselst.size()>0){
    // update cselst;
   //}

Thanks
GMASJ
 
Bryan Leaman 6Bryan Leaman 6
I think you just need to trim FWSubject and RWSubject. After replacing "FW:" with "" you'll still have the space that was between "FW:" and "Case for Testing".
Kaustubh LabheKaustubh Labhe
I am confused, 
for (Case c : [select id,casenumber,subject,ownerid,owner.name from case where id ='5002D000004JCQr']) 

your are looping for just 1 record?