动态 SOQL 查询
Dynamic SOQL Query
我正在尝试使用此代码获取动态结果,但它显示如下所示的错误。请帮助我使用此代码。
System.QueryException: Only variable references are allowed in dynamic SOQL/SOSL.
boolean first = true;
string database_query = '';
List<Schema.FieldSetMember> userfields = SObjectType.Task__c.FieldSets.Search.getFields();
for(Schema.FieldSetMember f : userfields) {
if (!first) {
database_query += ', ';
}
first = false;
database_query += f.getFieldPath();
}
if(Search_value != '' && database_query != ''){
TaskList = Database.query('select ' + database_query +',SOE__c from task__c where SOE__c =: \''+selectSOE +'\' and '+ selectedfield + ' like \'%' + Search_value +'%\'');
}
请尝试将查询中的“:=”替换为“=”。也看看这个问题的答案,我想你有类似的问题:
我正在尝试使用此代码获取动态结果,但它显示如下所示的错误。请帮助我使用此代码。
System.QueryException: Only variable references are allowed in dynamic SOQL/SOSL.
boolean first = true;
string database_query = '';
List<Schema.FieldSetMember> userfields = SObjectType.Task__c.FieldSets.Search.getFields();
for(Schema.FieldSetMember f : userfields) {
if (!first) {
database_query += ', ';
}
first = false;
database_query += f.getFieldPath();
}
if(Search_value != '' && database_query != ''){
TaskList = Database.query('select ' + database_query +',SOE__c from task__c where SOE__c =: \''+selectSOE +'\' and '+ selectedfield + ' like \'%' + Search_value +'%\'');
}
请尝试将查询中的“:=”替换为“=”。也看看这个问题的答案,我想你有类似的问题: