Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a String that contains some custom fields of Account. I want to pass a String in a Select query like this :

String myString = 'myCustomField1__c, myCustomField2__c';
List<Account> accounts = [SELECT Id, Name, myString FROM Account];

How can I do this ?

I'm able to do it with Database.query(...) but I'd prefer the method above if possible.

share|improve this question
up vote 5 down vote accepted

You can't combine SOQL and dynamic SOQL(Database.query(query_string)) - if you have to use this string with list of field you have to use dynamic SOQL.

share|improve this answer
Yes, that what i'm thinking. Thanks for the reply. – SF_user Apr 18 '14 at 12:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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