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
Priyanka BardhanPriyanka Bardhan 

Filtering long text area fields in SOQL to compare with Set

Hi All,
Can anyone help on the below?

Since we can't use text area fields in SOQL filter criterias, the alternative approach is to fetch all records and then iterate (using for loop) to check filter criteria using below snippet.
 
List<Account> filteredaccounts = new List<Account>();
for(Account act : [select id, name, textareaids__c from Account) {
    if(act.textareaids__c.contains('developer test')) {
        filteredaccounts.add(act);
    }
}
But how to do in case of comparing long text area with set of ids?
Example - 

textareaids__c = 'id1, id2, id3, id5';
Set variable which contains id4, id5, id3.

Here I want to compare and match inside for loop to get the filtered accounts. Since we got a match of id3 and id5, store the account record in list.


 
Amit Singh 1Amit Singh 1
Hi Priyanka,

For this, you need to use for inside for as your Text Area field contains multiple ids separated using a comma. Use code like below:
List<Account> filteredaccounts = new List<Account>();
Set<String> idsSet = new Set<String>(); // Your set which contains ids of the record
for(Account act : [select id, name, textareaids__c from Account) {
    if(act.textareaids__c !=null){
		List<String> idsList = textareaids__c.split(',');
		for(String str : idsList){
			if(idsSet.contains(str)){
				filteredaccounts.add(act);
			}
		}
	}
}
Thanks,
Amit