function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

how to select all fields from sobject.

please give me a query for this statement:


1)how to retrivew the field in a custom table by using soql query?


Hi  ,

  i am giving some of examples bellow , i think thsese are helpfull for u.

SELECT field1, field2, field3

FROM an object

WHERE filter statement(s) and (optionally) order the results



SELECT ID, Name,customfield__c from Lead WHERE email = ''

SELECT COUNT() from Lead WHERE email = ''

SELECT Id, Name from Lead WHERE email  LIKE '%somecomp%'

SELECT ProductCode FROM PricebookEntry WHERE CurrencyIsoCode = 'USD' or CurrencyIsoCode = 'GBP'

SELECT ProductCode,UnitPrice FROM PricebookEntry WHERE (UnitPrice >= 10 and CurrencyIsoCode='USD') OR (UnitPrice >= 5.47 and CurrencyIsoCode='EUR')


I think through soql we cant select  all by using *, we have to select all by separated ,  like

  select name,customfield__c........from demo___c;




Using Eclipse IDE and Salesforce schema you can select object that you want to query, it selects all fields automatically.

Copy that query and use it.



Srikanth. K


During runtime if you want to select all fields then  you first need to make a describesobject call. From this retrieve the complete list of fields and then form the query.

After this, pass the query to database.query(queryString) call to run the query.


To select all fields dynamically from any object you need to use Metadata API

you can use describe metadata API so you can choose all fields from that object.





This could be helpfull :


Map<String, Schema.SObjectField> M = Schema.SObjectType.Expense__c.fields.getMap();
System.Debug('@ > '+ M);
String strQ;
for(String strF:m.Keyset())

if(strQ == null)
strQ= strQ + ','+strF;
strQ='Select '+strQ+' from Expense__c limit2';
System.Debug('@Query >'+strQ);