I'm receiving a String query with query params (via URL), and one is mandatory and seven are optional. So if i don't receive a param, shouldn't be included in the query.
For instance:
My code is:
List<customObject__c> lstCstObj = [SELECT customField1__c, customField2__c, customField3__c, customField4__c, customField5__c FROM customObject__c WHERE customField2__c =: strVar1 + strCondition];
The value of strVar1 is the result of:
String.valueOf(RestContext.request.params.get('name'));
The value of strSurname is:
String strSurname = String.valueOf(RestContext.request.params.get('surname'));
And that give us the value of The value of strCondition (here is the problem) wich is:
String strCondition = '';
{...}
if(strSurname !=null){
strCondition = strCondition + ' AND (customField3__c =\''+ strSurname+ '\' OR customField3__c =\'' + strSurname+ '\' OR customField3__c =\''+ strSurname+'\')';
}
So if i write that it works, but obviously i can't because it's not a fixed value, depends of the query param:
SELECT customField1__c, customField2__c, customField3__c FROM customObject__c WHERE customField2__c =: strVar1 AND (customField3__c ='Doe' OR customField4__c='Doe' OR customField5__c='Doe')
The log returns:
strCondition: AND (customField3__c ='Doe' OR customField3__c ='Doe' OR customField3__c ='Doe')
customField2__c =: strVar1 + strCondition
- its not clear what you are doing - this is neither string nor direct SOQL. Can you show some more relevant code?