You need to sign in to do that
Don't have an account?
cyber surfer 18
iterating List values through a another List values
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?
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?
You can use Sets instead here..
Hope this helps!!