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
Preetham 345 SFDCPreetham 345 SFDC 

General SQL to SOQL

Hello Hi , 
I am a new to salesforce , Can any one please tell me why cant we execute Select * from .....  qurey in  SOQL editor. Is that not used in salesforce
And I have aquery which i have to execute in SOQL  which written in  general SQL. Could any one  help me on this .
The query should check for any column that have 10 or less entries. I don't know sosl/soql but if I were to write this in oracle sql it would look like below.

select * from <object/table> where <column/field> is not null and count (<column/field>) <= 10;

I think that would work and normally I would test it against a DB before sending out. It would just need to be run against all objects and each field.

Try this:

Select name from Contacts where Count(ID) < 10
Preetham 345 SFDCPreetham 345 SFDC
Hi Vinita, 
I have tried to execute the querry in which you gave in SOQL Editor console  , Its giving error saying 
[object Object]: WHERE expressions cannot use an aggregate operator, use a HAVING clause instead
is there any other way to proceed???
Hi Preetam, to answer your first question I dont believe that the select * feature is available in SOQL. 

If I understand your requirement correctly, you are looking out for a query that you can run on a particular object which returns the column names that have less than 10 entries. 

Unfortunately there is no direct way to do this using a single query. You can however do this by using Dynamic APEX loop through all the fields of a particular object and run the query something like 'select count(amount) from opportunity'. You then need to check if the count of entries is less than 2 or not. 

More information on dynamic apex
praveen murugesanpraveen murugesan
Hi Preetam,

For your first question there no such query like "select * from object"  in SOQL. I think to reduce the time and avoiding querying unwanted records salesforce is not providing this options. 

To achive this you can use like this 

DescribeSObjectResult res = binding.describeSObject( "Account" );
Field[] fields = res.getFields();
String expr = "";
for( int i=0; i < fields.length-1; i++ )
expr += fields[i].getName() + ", ";
expr += fields[ fields.length - 1 ].getName();

String qry = "Select " + expr + " from Account";

QueryResult res = binding.query( qry );

For the second question

You cant do in direct way. As Ramu's saidf you should use  dynamic query.


Praveen Murugesan
Preetham 345 SFDCPreetham 345 SFDC
Thank you every one for  your  kind reply for the question which i asked, It's really informative, I appreciate your quick response in letting me know the  things and improving my basic knowledge in salesforce.