You need to sign in to do that
Don't have an account?

salesforce Trailhead SOQL injection Challenge
Hi , I am also facing some problem with salesforce Trailhead SOQL injection Challenge, I tried many ways but still i am getting error .
can you suggest me where i am going wrong ?
Thank you
SOQL_Injection_Challenge:
public class SOQL_Injection_Challenge {
public string textual {get; set;}
public List<Supply__c> whereclause_records {get; set;}
//SELECT Id,Name,Quantity__c,Storage_Location__c,Type__c FROM Supply__c
public PageReference whereclause_search(){
string query = 'SELECT Id,Name,Quantity__c,Storage_Location__c,Storage_Location__r.Castle__c,Type__c FROM Supply__c';
string whereClause = '';
if(textual != null && textual!=''){
whereClause += 'name like \'%'+textual+'%\' ';
}
if(whereClause != ''){
whereclause_records = database.query(query+' where '+whereClause+' Limit 10');
validate(whereClause,whereclause_records.size());
}
return null;
}
public void validate(string s, integer i){
if(s.contains('\'%') && s.containsIgnoreCase('Nobles_Only__c') && s.contains('%\'') && i<10){
cvcs__c v = cvcs__c.getInstance('sic1');
if(v==null){
v = new cvcs__c(name='sic1',c1__c = 1);
} else {
v.c1__c += 1;
}
upsert v;
}
}
}
can you suggest me where i am going wrong ?
Thank you
SOQL_Injection_Challenge:
public class SOQL_Injection_Challenge {
public string textual {get; set;}
public List<Supply__c> whereclause_records {get; set;}
//SELECT Id,Name,Quantity__c,Storage_Location__c,Type__c FROM Supply__c
public PageReference whereclause_search(){
string query = 'SELECT Id,Name,Quantity__c,Storage_Location__c,Storage_Location__r.Castle__c,Type__c FROM Supply__c';
string whereClause = '';
if(textual != null && textual!=''){
whereClause += 'name like \'%'+textual+'%\' ';
}
if(whereClause != ''){
whereclause_records = database.query(query+' where '+whereClause+' Limit 10');
validate(whereClause,whereclause_records.size());
}
return null;
}
public void validate(string s, integer i){
if(s.contains('\'%') && s.containsIgnoreCase('Nobles_Only__c') && s.contains('%\'') && i<10){
cvcs__c v = cvcs__c.getInstance('sic1');
if(v==null){
v = new cvcs__c(name='sic1',c1__c = 1);
} else {
v.c1__c += 1;
}
upsert v;
}
}
}
I think this has to be changed like this :
All Answers
I think this has to be changed like this :
I am still getting this error when i tried your answer.
"Error: Compile Error: Method does not exist or incorrect signature: void escapeSingleQuotes() from the type String at line 14 column 57"
but still the challegene is throwing the error :(
Challenge Not yet complete... here's what's wrong:
It doesn't appear that you've successfully performed a SOQL injection using the Visualforce page. Take a look at the hint above and please try again.
You are looking into the wrong class. It is "Prevent_SOQL_Injection_Challenge" not "SOQL_Injection_Challenge".
Actually i am looking at SOQL injection challenge only , but i am mistaken that code needs to be changed in that challenge which is wrong , i needed to perform the search query for injecting it and retierve one record .
Thank you once again :)
%' and Nobles_only__c=True and name like '%Ven
Iam getting this error
It doesn't appear that you've successfully performed a SOQL injection using the Visualforce page. Take a look at the hint above and please try again.
You can pass this by entering the following search expression -
%' and Nobles_Only__c = True and name like '%
Since you dont know the supply name hence [name like '%Ven] is not a correct add to the expression @Varun Arora