3
String str = 'Order';

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

Can we query like this, I want to query dynamically

1
  • Yes, that is possible. Try googling for "Apex dynamic SOQL". Or is there any specific problem you run into? Commented Apr 20, 2016 at 9:58

1 Answer 1

5

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);

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.