I am facing some issues with following SOQL Query :
My Scanner result gave me SOQL Injection Errors, can anyone help in fixing those –
I am going throw lots of Google Search and Stuff, but it will be great if I am able to fix these ASAP.
1)
String query = 'SELECT Id,Subject,Status,OwnerId,Owner.Name,Owner.IsActive,ActivityDate FROM Task WHERE OwnerId in (SELECT ID FROM User WHERE isActive = true) AND ActivityDate ='+ selected;
2)
myuserid=ApexPages.currentPage().getParameters().get('userid');
filter =ApexPages.currentPage().getParameters().get('Filter');
squery = 'SELECT Id,Subject,Status,OwnerId,Owner.Name,Owner.IsActive,Priority,ActivityDate,ReminderDateTime,Whoid,Who.name FROM Task WHERE OwnerId=\'' + myuserid +
'\' AND ActivityDate='+filter;
List<Task> lsttask = Database.Query**(String.escapeSingleQuotes(squery));**
ERROR :
System.QueryException: line 1:137 no viable alternative at character
'\'
Best Answer
The salesforce security scanner should of give you some potential mitigation information such as:
You can use the
escapeSingleQuotes
method in the following way:More information on escapeSingleQuotes can be found here