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

Unable to query the records using dynamic query
Hi All,
Unable to query the records using dynamic query. Can any one help me to solve the below query..
Here selectionApiname and SelectionFieldId's are dynamic variables.
if(id!=null){
selectionApiname = 'Id';
SelectionFieldId = ''\''001..'\'''
}
else{
selectionApiname = 'Name';
SelectionFieldId = ''\''TestName'\''';
}
Please find the below code
Datetime createdstartdate =2015-01-10T12:00:00Z ;
DateTime createdenddate =2015-01-30T12:00:00Z ;
String selectionApiname = 'Id';
String SelectionFieldId = '001.....'
String accountRecords = 'select Id From account'
+ 'where (createdDate >= '
+createdstartdate.format('yyyy-MM-dd') + 'T' + createdstartdate.format('hh:mm:ss') + 'Z'
+ ' and createdDate <='
+createdenddate.format('yyyy-MM-dd') + 'T' + createdenddate.format('hh:mm:ss') + 'Z'+')'
+ ' or '+'('+selectionAPIName+ ' In '+selectionFieldid+')'
+'limit 10';
List<Account> acc = Database.query(accountRecords);
Unable to query the records using dynamic query. Can any one help me to solve the below query..
Here selectionApiname and SelectionFieldId's are dynamic variables.
if(id!=null){
selectionApiname = 'Id';
SelectionFieldId = ''\''001..'\'''
}
else{
selectionApiname = 'Name';
SelectionFieldId = ''\''TestName'\''';
}
Please find the below code
Datetime createdstartdate =2015-01-10T12:00:00Z ;
DateTime createdenddate =2015-01-30T12:00:00Z ;
String selectionApiname = 'Id';
String SelectionFieldId = '001.....'
String accountRecords = 'select Id From account'
+ 'where (createdDate >= '
+createdstartdate.format('yyyy-MM-dd') + 'T' + createdstartdate.format('hh:mm:ss') + 'Z'
+ ' and createdDate <='
+createdenddate.format('yyyy-MM-dd') + 'T' + createdenddate.format('hh:mm:ss') + 'Z'+')'
+ ' or '+'('+selectionAPIName+ ' In '+selectionFieldid+')'
+'limit 10';
List<Account> acc = Database.query(accountRecords);

what's that T/Z ? You might missed some branket there.