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
ashish jadhav 9ashish jadhav 9 

What is equivalent to ' SELECT * FROM ACCOUNT' is SOQL?

How can I know the number of fields in an object and how can I append entire fields at once? Please guide.
Best Answer chosen by ashish jadhav 9
Rohit K SethiRohit K Sethi
Hi,

For all the field of any object follow the steps :

1. Open Developer Console.
2. Press ctrl + o .
3. Go to object section and select desire object like "Account" click on "Open". 
4. All the field of selected object is shown in table.
5. Select fields which you want and click on query button then the selected field shown in query editor.


Thanks.

All Answers

Rohit K SethiRohit K Sethi
Hi,

For all the field of any object follow the steps :

1. Open Developer Console.
2. Press ctrl + o .
3. Go to object section and select desire object like "Account" click on "Open". 
4. All the field of selected object is shown in table.
5. Select fields which you want and click on query button then the selected field shown in query editor.


Thanks.
This was selected as the best answer
Rohit K SethiRohit K Sethi
Hi ,

If you want to use dynamic field in apex code then use below code :
 
Set<String> accFieldList = Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap().keySet();
List<String> strList = new List<String>();
strList.addAll(accFieldList);
String fields = string.join(strList,',');
system.debug(fields);

Thanks.
Amit Chaudhary 8Amit Chaudhary 8
You can use the Apex Describe command
1) http://amitsalesforce.blogspot.com/2016/03/dynamic-query-select-all-field-in-soql.html

Sample code for you
public Void GetAllField()
{
 String query ='';
 String SobjectApiName = 'Account';
 Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
 Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap();

 String strFields = '';
 
 for(String fieldName : fieldMap.keyset() )
 {
  if(strFields == null || strFields == '')
  {
   strFields = fieldName;
  }else{
   strFields = strFields + ' , ' + fieldName;
  }
 }

 query = 'select ' + strFields + ' from ' + SobjectApiName + ' Limit 10 ';

 List <Account> accList = Database.query(query);
 
}

Let us know if this will help you
 
Jordan StarrJordan Starr
This works for me.
SELECT Id, Name FROM Account Where Name != ''

 
Aman ChawlaAman Chawla
As of API 51.0, we can run the command
SELECT FIELDS(ALL) FROM <OBJECT_API_NAME>

Also, be careful as we need to limit this by 200 otherwise you wont see results or will get an error. :) 

Cheers!