2
String str = 'Order';

List<SObject> listData = [Select Id From str ];

Can we query like this, I want to query dynamically

  • Yes, that is possible. Try googling for "Apex dynamic SOQL". Or is there any specific problem you run into? – rael_kid Apr 20 '16 at 9:58
2

Try like this

String str = 'Account';
String strQuery = 'SELECT Id, Name FROM '+str ;
system.debug(Database.query(strQuery));

In your case

String str = 'Order';
String strQuery = 'SELECT Id, Name FROM '+str ;
List<SObject> listData = Database.query(strQuery);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.