You need to sign in to do that
Don't have an account?
Preetham 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.
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
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???
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
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_describe_objects_understanding.htm
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.
Thanks,
Praveen Murugesan