Take the 2-minute tour ×
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.

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

1 Answer 1

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.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_soql.htm

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

Your Answer

 
discard

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.