Skip to content

Commit a5aaa3a

Browse files
committed
Update README.md
1 parent f7492f4 commit a5aaa3a

File tree

1 file changed

+89
-9
lines changed

1 file changed

+89
-9
lines changed

README.md

Lines changed: 89 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,98 @@ Installation
3131
------------
3232

3333
This library is available on [Packagist](http://packagist.org/packages/phpforce/soap-client).
34-
The recommended way to install this library is through [Composer](http://getcomposer.org).
34+
The recommended way to install this library is through [Composer](http://getcomposer.org):
3535

36-
To install it, add the following to your `composer.json`:
36+
```bash
37+
$ php composer.phar require phpforce/soap-client dev-master
38+
```
39+
40+
Usage
41+
-----
42+
43+
### The client
44+
45+
Use the client to query and manipulate your organisation’s Salesforce data. First construct a client using the builder:
46+
47+
```php
48+
$builder = new \Phpforce\SoapClient\ClientBuilder(
49+
'/path/to/your/salesforce/wsdl/sandbox.enterprise.wsdl.xml'
50+
'username',
51+
'password',
52+
'security_token'
53+
);
54+
55+
$client = $builder->build();
56+
```
57+
58+
### SOQL queries
59+
60+
```php
61+
$result = $client->query('select Name, SystemModstamp from Account limit 5');
62+
```
63+
64+
This will fetch five accounts from Salesforce and return them as a
65+
`RecordIterator`. You can now iterate over the results. The account’s
66+
`SystemModstamp` is returned as a `\DateTime` object:
67+
68+
```php
69+
foreach ($results as $account) {
70+
echo 'Last modified: ' . $account->SystemModstamp->format('Y-m-d H:i:') . "\n";
71+
}
72+
```
3773

38-
```JSON
39-
{
40-
"require": {
41-
...
42-
"phpforce/soap-client": "dev-master",
43-
...
74+
### One-to-many relations (subqueries)
75+
76+
Results from [subqueries](http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select.htm)
77+
are themselves returned as record iterators. So:
78+
79+
```php
80+
$accounts = $client->query(
81+
'select Id, (select Id, Name from Contacts) from Account limit 10'
82+
);
83+
84+
foreach ($accounts as $account) {
85+
if (isset($account->Contacts)) {
86+
foreach ($account->Contacts as $contact) {
87+
echo sprintf("Contact %s has name %s\n", $contact->Id, $contact->Name);
88+
}
4489
}
4590
}
4691
```
4792

48-
And run `$ php composer.phar install`.
93+
### Fetching large numbers of records
94+
95+
If you issue a query that returns over 2000 records, only the first 2000 records
96+
will be returned by the Salesforce API. Using the `queryLocator`, you can then
97+
fetch the following results in batches of 2000. The record iterator does this
98+
automatically for you:
99+
100+
```php
101+
$accounts = $client->query('Select Name from Account');
102+
echo $accounts->count() . ' accounts returned';
103+
foreach ($accounts as $account) {
104+
// This will iterate over the 2000 first accounts, then fetch the next 2000
105+
// and iterate over these, etc. In the end, all your organisations’s accounts
106+
// will be iterated over.
107+
}
108+
```
109+
110+
### Logging
111+
112+
To enable logging for the client, call `withLog()` on the builder. For instance when using [Monolog](https://github.com/Seldaek/monolog):
113+
114+
```php
115+
$log = new \Monolog\Logger('name');
116+
$log->pushHandler(new \Monolog\Handler\StreamHandler('path/to/your.log'));
117+
118+
$builder = new \Phpforce\SoapClient\ClientBuilder(
119+
'/path/to/your/salesforce/wsdl/sandbox.enterprise.wsdl.xml'
120+
'username',
121+
'password',
122+
'security_token'
123+
);
124+
$client = $builder->withLog($log)
125+
->build();
126+
```
127+
128+
All requests to the Salesforce API, as well as the responses and any errors that it returns, will now be logged.

0 commit comments

Comments
 (0)