I was going through the SOQL documentation , but couldn\'t find query to fetch all the field data of an entity say , Account , like
select * from Account
For me it was the first time with Salesforce today and I came up with this in Java:
/**
* @param o any class that extends {@link SObject}, f.ex. Opportunity.class
* @return a list of all the objects of this type
*/
@SuppressWarnings("unchecked")
public List getAll(Class o) throws Exception {
// get the objectName; for example "Opportunity"
String objectName= o.getSimpleName();
// this will give us all the possible fields of this type of object
DescribeSObjectResult describeSObject = connection.describeSObject(objectName);
// making the query
String query = "SELECT ";
for (Field field : describeSObject.getFields()) { // add all the fields in the SELECT
query += field.getName() + ',';
}
// trim last comma
query = query.substring(0, query.length() - 1);
query += " FROM " + objectName;
SObject[] records = connection.query(query).getRecords();
List result = new ArrayList();
for (SObject record : records) {
result.add((O) record);
}
return result;
}