I am facing soql injection issue in my dynamic query, i have done with sting.escapesinglequotes()
also but still facing this issue.
here is my code.
query: query = 'select id,Name,Owner.Id from ' + ObjectSelected + ' where ownerid =\'' + String.escapeSingleQuotes(objCurrentOwner) + '\'' +getfilters();
Method:
public string getfilters(){
system.debug('inMethod@@@@');
string filter = '';
for(FilterWrapper fw:lstFldWrap){
if(fw.field!='--select field--' && fw.operand!=NULL && fw.operand!='')
{
if(fw.operator.contains('LIKE')){
if(!fw.operator.contains('NOT'))
{ filter+= ' AND '+fw.field+' '+fw.operator.replace('{val}',fw.operand); }
else
{ filter+= ' AND (NOT '+fw.field+' '+fw.operator.replace('NOT','').replace('{val}',fw.operand)+')'; }
}
else{
if(fieldMap.keyset().contains(fw.field))
{
string FldType = string.valueOf(fieldMap.get(fw.field).getDescribe().getType());
system.debug('ftype**'+FldType);
fw.operand = '\''+fw.operand+'\'';
system.debug('operand' +fw.operand);
if(FldType=='DATE' || FldType=='DATETIME' || FldType=='CURRENCY' || FldType=='DOUBLE' || FldType=='INTEGER'){
fw.operand = fw.operand.replace('\'','');
system.debug('operand' +fw.operand);
}
filter+= ' AND '+fw.field+fw.operator+fw.operand;
}
}
system.debug('filter***' +filter);
// if(fw.field.contains('date'))
// filter = filter.replace('\'','');
}
}
system.debug('Filter****' +filter);
String.escapeSingleQuotes(filter);
return filter;
}