Newer Version Available
Improving Performance by Not Searching on Null Values
In your SOQL and SOSL queries, avoid searching records that contain null
values. Filter out null values first to improve performance. In the following example, any
records where the treadID value is null are
filtered out of the returned
values.
1Public class TagWS {
2
3/* getThreadTags
4*
5* a quick method to pull tags not in the existing list
6*
7*/
8public static webservice List<String>
9 getThreadTags(String threadId, List<String> tags) {
10 system.debug(LoggingLevel.Debug,tags);
11
12 List<String> retVals = new List<String>();
13 Set<String> tagSet = new Set<String>();
14 Set<String> origTagSet = new Set<String>();
15 origTagSet.addAll(tags);
16
17// Note WHERE clause verifies that threadId is not null
18
19 for(CSO_CaseThread_Tag__c t :
20 [SELECT Name FROM CSO_CaseThread_Tag__c
21 WHERE Thread__c = :threadId AND
22 threadID != null])
23
24{
25 tagSet.add(t.Name);
26}
27 for(String x : origTagSet) {
28 // return a minus version of it so the UI knows to clear it
29 if(!tagSet.contains(x)) retVals.add('-' + x);
30}
31 for(String x : tagSet) {
32 // return a plus version so the UI knows it's new
33 if(!origTagSet.contains(x)) retvals.add('+' + x);
34}
35
36 return retVals;
37}