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
eddie129eddie129 

SOQL question

Hi all,
I am trying to get all contact data by using query() method with SOQL: "Select Id, LastName, FirstName,... From contact".
Is there any simple statement can do the same thing? (such as "Select * From contact" in SQL)
 
Thanks in advance.
hemmhemm
You are doing the right thing.  There's 1 catch, though.  SOQL works in batches.  When your dataset is returned, there is a parameter called done that will either be true of false.  If its false, then that means you have more data to get.  You then need to call the QueryMore method.  Simple PHP code example below:

Code:
$queryString = "Select Id, Name from Account ";
$queryResult = $sfdc->query($queryString);

do {

// Do whatever logic you need to against the dataset.

// Check if the result is "done".
$done = $queryResult->done;
if ($done != "1")
{
$queryResult = $sfdc->queryMore($queryResult->queryLocator);
}

}while ($done != "1");

 

eddie129eddie129

Thanks, but my question is about statement, not usage, I should describe my question more clearly.

What I need is a simple term to represent all field in contact object. For example, If I want to get all field data in contact, there are 40 fields need to be written in following statements : (It's too long to be maintained)

"Select Id, LastName, FirstName, Salutation, RecordTypeId, OtherStreet,... From contact"

I want to know if there have a simple term which can replace the field list, so we only need to write:

"Select * From contact"

Is this simple term exist?

 

SuperfellSuperfell
No, there is no select * from foo. If you're using the partner WSDL, then you can use the describeSObject call to dynamically build the list of fields.
Jack SenechalJack Senechal
Hi Eddie,

I just posted a related problem, but maybe this will help with yours. I wrote this PHP function to get a list of fields for SOQL queries:

    /**
     * Get a comma separated list of the fields in an object
     *
     * @param string $object_name The name of the object you want the fields from
     * @return string
     */
    public function get_field_list($object_name)
    {
        $desc = $this->sf_client->describeSObject($object_name);
        $fields = array();
        foreach ($desc->fields as $field)
        {
            $fields[] = $field->name;
        }
        $result = join(',', $fields);
        return $result;
    }