You need to sign in to do that
Don't have an account?
Roger Pavelle
System.QueryException: value of filter
I can't figure out why I am getting the following error:
System.QueryException: value of filter criterion for field 'Edibility__c' must be of type string and should be enclosed in quotes
The checkboxes call the setCheckBoxValue function, which is supposed to track whether the box is checked or not. This array is later used by the buildWhereClause function to rerender a search results table based on the chekced values. There are 61 checkboxes and all but the first 4 checkboxes work correctly. Everything was working for a while, but then a change in the custom object led me to change the "value" field, but I later changed it back to what it used to be (even going so far as to copy the code from other boxes and changing the value).
Why doesn't this work anymore?
Apex code:
<apex:inputCheckbox label="Choice" id="edibilityChoiceChk" >
<apex:actionSupport action="{!setChkBoxValue}" event="onchange" rerender="bolete_list">
<apex:param name="boxNum" value="0"/>
</apex:actionSupport>
</apex:inputCheckbox>
Controller code (selected pieces):
private List<String> whereClauseValues = new List<String>{'4', '3', '2', '1', 'poreColorRed__c', 'poreColorBrown__c',
'sporePrintYellow__c', 'sporePrintPink__c', 'sporePrintBrown__c'};
public void setChkBoxValue()
{
integer boxNum = integer.valueOf(system.currentPageReference().getParameters().get('boxNum'));
boolean before = chkBoxValues[boxNum];
chkBoxValues[boxNum] = !chkBoxValues[boxNum];
System.debug('boxNum:' + boxNum + ' before:' + before);
System.debug(currentChkBoxValues);
}
private void buildWhereClause()
{
Boolean exists = false;
whereClause = '';
//The first four values are for edibility, which are not mutually exclusive, so they are built
// using or instead of and
for (Integer i = 0; i<4; i++)
{
if (chkBoxValues[i])
{
if (exists)
{
whereClause = whereClause + ' or Edibility__c = ' + string.escapeSingleQuotes(whereClauseValues[i]);
}
else
{
whereClause = 'Where (Edibility__c = ' + string.escapeSingleQuotes(whereClauseValues[i]);
exists = true;
}
}
}
if (exists)
{
whereClause = whereClause + ') ';
}
//All the other values are individual values, so they are built with AND
for (Integer i = 4; i<whereClauseValues.size(); i++)
{
if (chkBoxValues[i])
{
if (exists)
{
whereClause = whereClause + 'and ' + whereClauseValues[i] + ' = true ';
}
else
{
whereClause = 'Where ' + whereClauseValues[i] + ' = true ';
exists = true;
}
}
}
}
System.QueryException: value of filter criterion for field 'Edibility__c' must be of type string and should be enclosed in quotes
The checkboxes call the setCheckBoxValue function, which is supposed to track whether the box is checked or not. This array is later used by the buildWhereClause function to rerender a search results table based on the chekced values. There are 61 checkboxes and all but the first 4 checkboxes work correctly. Everything was working for a while, but then a change in the custom object led me to change the "value" field, but I later changed it back to what it used to be (even going so far as to copy the code from other boxes and changing the value).
Why doesn't this work anymore?
Apex code:
<apex:inputCheckbox label="Choice" id="edibilityChoiceChk" >
<apex:actionSupport action="{!setChkBoxValue}" event="onchange" rerender="bolete_list">
<apex:param name="boxNum" value="0"/>
</apex:actionSupport>
</apex:inputCheckbox>
Controller code (selected pieces):
private List<String> whereClauseValues = new List<String>{'4', '3', '2', '1', 'poreColorRed__c', 'poreColorBrown__c',
'sporePrintYellow__c', 'sporePrintPink__c', 'sporePrintBrown__c'};
public void setChkBoxValue()
{
integer boxNum = integer.valueOf(system.currentPageReference().getParameters().get('boxNum'));
boolean before = chkBoxValues[boxNum];
chkBoxValues[boxNum] = !chkBoxValues[boxNum];
System.debug('boxNum:' + boxNum + ' before:' + before);
System.debug(currentChkBoxValues);
}
private void buildWhereClause()
{
Boolean exists = false;
whereClause = '';
//The first four values are for edibility, which are not mutually exclusive, so they are built
// using or instead of and
for (Integer i = 0; i<4; i++)
{
if (chkBoxValues[i])
{
if (exists)
{
whereClause = whereClause + ' or Edibility__c = ' + string.escapeSingleQuotes(whereClauseValues[i]);
}
else
{
whereClause = 'Where (Edibility__c = ' + string.escapeSingleQuotes(whereClauseValues[i]);
exists = true;
}
}
}
if (exists)
{
whereClause = whereClause + ') ';
}
//All the other values are individual values, so they are built with AND
for (Integer i = 4; i<whereClauseValues.size(); i++)
{
if (chkBoxValues[i])
{
if (exists)
{
whereClause = whereClause + 'and ' + whereClauseValues[i] + ' = true ';
}
else
{
whereClause = 'Where ' + whereClauseValues[i] + ' = true ';
exists = true;
}
}
}
}
final code for the first four boxes:
for (Integer i = 0; i<4; i++)
{
if (chkBoxValues[i])
{
if (exists)
{
whereClause = whereClause + ' or (Edibility__c = ' + whereClauseValues[i] + ')';
}
else
{
whereClause = 'Where ((Edibility__c = ' + whereClauseValues[i] + ')';
exists = true;
}
}
}
if (exists)
{
whereClause = whereClause + ') ';
}
All Answers
Controller code to display values:
public string currentChkBoxValues
{
get {
return string.join(chkBoxValues, ', ');
}
}
public string currentWhereClause
{
get {
return whereClause;
}
}
final code for the first four boxes:
for (Integer i = 0; i<4; i++)
{
if (chkBoxValues[i])
{
if (exists)
{
whereClause = whereClause + ' or (Edibility__c = ' + whereClauseValues[i] + ')';
}
else
{
whereClause = 'Where ((Edibility__c = ' + whereClauseValues[i] + ')';
exists = true;
}
}
}
if (exists)
{
whereClause = whereClause + ') ';
}