Skip to main content
added 329 characters in body
Source Link
sfdcfox
  • 501.6k
  • 21
  • 473
  • 828

You want to use Object as a generic class to use. Also, no need to check null AND an empty string (it'll always be null or a non-empty string). Here's the modifications you want:

public class Criteria {
   public String FieldName; 
   public String Operator;      
   public Object FieldValue;
   public Criteria(String f_name, Object f_value) {
       FieldName = f_name;
       FieldValue = f_value;
       Operator = '=';
   }
   public String getSOQLCriteria() {
       returnif(FieldValue fieldNameinstanceOf +String) '{
 '  + Operator + ' \''    return FieldName + FieldValueOperator + '\'';String.escapeSingleQuotes(String.valueOf(FieldValue));
       }
       return FieldName + Operator + FieldValue;
   }
   public String IsFieldValueGiven() {
       return FieldValue != null;
   }
}

The actual getSOQLCriteria method would need to check the data type of the field value to determine the appropriate method to use. The above method should work for all primitive data types.

You want to use Object as a generic class to use. Also, no need to check null AND an empty string (it'll always be null or a non-empty string). Here's the modifications you want:

public class Criteria {
   public String FieldName; 
   public String Operator;      
   public Object FieldValue;
   public Criteria(String f_name, Object f_value) {
       FieldName = f_name;
       FieldValue = f_value;
       Operator = '=';
   }
   public String getSOQLCriteria() {
       return fieldName + ' '  + Operator + ' \'' + FieldValue + '\'';
   }    
   public String IsFieldValueGiven() {
       return FieldValue != null;
   }
}

You want to use Object as a generic class to use. Also, no need to check null AND an empty string (it'll always be null or a non-empty string). Here's the modifications you want:

public class Criteria {
   public String FieldName; 
   public String Operator;      
   public Object FieldValue;
   public Criteria(String f_name, Object f_value) {
       FieldName = f_name;
       FieldValue = f_value;
       Operator = '=';
   }
   public String getSOQLCriteria() {
       if(FieldValue instanceOf String) {
           return FieldName + Operator + String.escapeSingleQuotes(String.valueOf(FieldValue));
       }
       return FieldName + Operator + FieldValue;
   }
   public String IsFieldValueGiven() {
       return FieldValue != null;
   }
}

The actual getSOQLCriteria method would need to check the data type of the field value to determine the appropriate method to use. The above method should work for all primitive data types.

Source Link
sfdcfox
  • 501.6k
  • 21
  • 473
  • 828

You want to use Object as a generic class to use. Also, no need to check null AND an empty string (it'll always be null or a non-empty string). Here's the modifications you want:

public class Criteria {
   public String FieldName; 
   public String Operator;      
   public Object FieldValue;
   public Criteria(String f_name, Object f_value) {
       FieldName = f_name;
       FieldValue = f_value;
       Operator = '=';
   }
   public String getSOQLCriteria() {
       return fieldName + ' '  + Operator + ' \'' + FieldValue + '\'';
   }    
   public String IsFieldValueGiven() {
       return FieldValue != null;
   }
}