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
C. Praveen kumarC. Praveen kumar 

Why doesnt Salesforce support "*"in SOQL Query?

Why doesnt Salesforce support "*"in SOQL Query when we can use a Dynamic Query to retrieve all fields of an object.

What are the reasons for not able to include an "*" operator in a query?
NagaNaga (Salesforce Developers) 
Hi Praveen,

We dont need "*" in SOQL.For example, the following SOQL query returns the value of the Id and Name field for all Account records if the value of Name is Sandy:
view source


1 SELECT Id, Name
2 FROM Account
3 WHERE Name = 'Sandy'

Best Regards
Naga Kiran
AmrenderAmrender
Hi Praveen

"*" in SQL is used to retrieve all the coulmn/fields of that particular table/object.

Salesforce is a multitenant environment and we are bound to governor limit.To make quries more efficient and to avoid hitting governor limits, salesforce does not allow to use "*" in SOQL queries.

Regards
Amrender
Amit Chaudhary 8Amit Chaudhary 8
HI Praveen,

I agree with Amrender comment. 
Salesforce is a multitenant environment and we are bound to governor limit.To make quries more efficient and to avoid hitting governor limits, salesforce does not allow to use "*" in SOQL queries.

If you still want to fatch all field then please try below code
public class selectAllSOQLExampleController {
    public List<Account> accList{get;set;}
    public String query{get;set;}
    public selectAllSOQLExampleController(){
    }
    public PageReference fetch(){
        String SobjectApiName = 'Account';
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap();
 
        String commaSepratedFields = '';
        for(String fieldName : fieldMap.keyset()){
            if(commaSepratedFields == null || commaSepratedFields == ''){
                commaSepratedFields = fieldName;
            }else{
                commaSepratedFields = commaSepratedFields + ', ' + fieldName;
            }
        }
 
        query = 'select ' + commaSepratedFields + ' from ' + SobjectApiName + ' Limit 5';
 
        accList = Database.query(query);
 
        return null;
    }
}
http://www.sfdcpoint.com/salesforce/dynamic-soql-query-fetch-fields-object-salesforce/

I hope that will help you. Please let us know if this will help you

Thanks
Amit Chaudhary
 
Nishad BashaNishad Basha
Hi, Amit Chaudhary 8

 content type as xml format using future(callout=true) in salesforce using trigger
How to write the above scenario.And how to run the future(callout=true) in developer console.please give me the examples on that.