• cyber surfer 18
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hi All,

I have a requirement where I am required to search if a field from list<customobject> contains any one value from anoher list.

here the field is a LongTextArea hence i am not able to use any formula , as i have long list of Keywords which i need to check i have written below logic.

String alp ;
List<String> lstAlpha =  new List<String>{'Keyword 1','Keyword 2','Keyword 3'}; // List of Keywords to be searched
integer i = 0;
System.debug('List Values--->'+lstAlpha);
List<Abc__c> lst = [SELECT id,name,LongTextAreafield__c from Abc__c where status = 'open'];
for( Abc__c ls:lst)
{
    alp = ls.LongTextAreafield__c;
    // iterating one list in another
    do {
        if (alp.contains(lstAlpha[i])) // checking 1st list field contains keyword or not
        {system.debug ('Check Successfull');  }
        System.debug('Value of i =====>>>>'+i);
        i++;
    }
    while (i < lstAlpha.size());
    // I can use any loop but as its not best practice I want to aviod nested loops

}
system.debug ('alp contents ==== '+alp);


Issue here is I had to use Nested loops which is not best practice can anyone suggest a better solution to this requirement?