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.
Public class TagWS {

/* getThreadTags
*
* a quick method to pull tags not in the existing list
*
*/
public static webservice List<String> 
       getThreadTags(String threadId, List<String> tags) {
   system.debug(LoggingLevel.Debug,tags);

   List<String> retVals = new List<String>();
   Set<String> tagSet = new Set<String>();
   Set<String> origTagSet = new Set<String>();
   origTagSet.addAll(tags);

// Note WHERE clause verifies that threadId is not null

   for(CSO_CaseThread_Tag__c t : 
      [SELECT Name FROM CSO_CaseThread_Tag__c 
      WHERE Thread__c = :threadId AND
      WHERE threadID != null]) 

{
   tagSet.add(t.Name);
}
   for(String x : origTagSet) { 
   // return a minus version of it so the UI knows to clear it
      if(!tagSet.contains(x)) retVals.add('-' + x);
}
   for(String x : tagSet) { 
   // return a plus version so the UI knows it's new
      if(!origTagSet.contains(x)) retvals.add('+' + x);
}

   return retVals;
} 
Previous
Next