| 1 |
<?php
|
| 2 |
|
| 3 |
/*
|
| 4 |
* Client sample that performs set of basic salesforce API operations.
|
| 5 |
*/
|
| 6 |
|
| 7 |
require_once('salesforce.php');
|
| 8 |
|
| 9 |
// test code
|
| 10 |
$username = 'steve@raincitystudios.com';
|
| 11 |
$password = 'l3tme1n';
|
| 12 |
|
| 13 |
// create client and login
|
| 14 |
$sfdc = new salesforce('partner.wsdl');
|
| 15 |
$loginResult = $sfdc->login($username, $password);
|
| 16 |
|
| 17 |
//set batch size header
|
| 18 |
$batchSize = new soapval('batchSize', null, 2);
|
| 19 |
$sfdc->setHeader('QueryOptions', array($batchSize));
|
| 20 |
|
| 21 |
if (!$loginResult){
|
| 22 |
|
| 23 |
print_r("\nfailed login: \n\n");
|
| 24 |
print_r($sfdc->result);
|
| 25 |
|
| 26 |
} else {
|
| 27 |
|
| 28 |
|
| 29 |
# if you want to use a local proxy, uncomment this out
|
| 30 |
# $sfdc->setURL('http://localhost:81/services/Soap/u/6.0');
|
| 31 |
|
| 32 |
// simple call, showing XML request and response
|
| 33 |
$response = $sfdc->getServerTimestamp();
|
| 34 |
// print_r($sfdc->client->request);
|
| 35 |
// print_r($sfdc->client->response);
|
| 36 |
print_r("\ngetServerTimestamp: \n\n");
|
| 37 |
print_r($response);
|
| 38 |
$startDate = $response;
|
| 39 |
|
| 40 |
// create Contact
|
| 41 |
$contact = new sObject('Contact',
|
| 42 |
null,
|
| 43 |
array(
|
| 44 |
'FirstName' => 'TestFirstName',
|
| 45 |
'LastName' => 'TestLastName',
|
| 46 |
'Phone' => '555-555-1212',
|
| 47 |
'Fax' => '444-444-1212'
|
| 48 |
)
|
| 49 |
);
|
| 50 |
$createResult = $sfdc->create($contact);
|
| 51 |
print_r("\ncreate one: \n\n");
|
| 52 |
print_r($createResult);
|
| 53 |
|
| 54 |
// query Contact by ID
|
| 55 |
$id = $createResult['id'];
|
| 56 |
$queryResult = $sfdc->query("select id, firstname, lastname, phone, fax from contact where id = '$id'");
|
| 57 |
print_r("\nquery by id: \n\n");
|
| 58 |
print_r($queryResult);
|
| 59 |
|
| 60 |
// update Contact
|
| 61 |
$contact1 = new sObject('Contact',
|
| 62 |
$id,
|
| 63 |
array(
|
| 64 |
'FirstName' => 'TestFirstName',
|
| 65 |
'LastName' => 'TestLastNameUpdate'
|
| 66 |
),
|
| 67 |
array('Phone', 'Fax')
|
| 68 |
);
|
| 69 |
$updateResult = $sfdc->update($contact1);
|
| 70 |
print_r("\nupdate one: \n\n");
|
| 71 |
print_r($updateResult);
|
| 72 |
|
| 73 |
// query updated Contact by ID
|
| 74 |
$queryResult = $sfdc->query("select id, firstname, lastname, phone, fax from contact where id = '$id'");
|
| 75 |
print_r("\nquery by id: \n\n");
|
| 76 |
print_r($queryResult);
|
| 77 |
|
| 78 |
// retrieve by ID
|
| 79 |
$retrieveResult = $sfdc->retrieve("id, firstname, lastname", "contact", array($id, $id));
|
| 80 |
print_r("\nretrieve: \n\n");
|
| 81 |
print_r($retrieveResult);
|
| 82 |
|
| 83 |
// delete contact
|
| 84 |
$deleteResult = $sfdc->delete($createResult['id']);
|
| 85 |
$id = $deleteResult['id'];
|
| 86 |
print_r("\ndelete one ($id): \n\n");
|
| 87 |
print_r($deleteResult);
|
| 88 |
|
| 89 |
// bulk create Contacts
|
| 90 |
$contacts = array($contact, $contact);
|
| 91 |
$createResult = $sfdc->create($contacts);
|
| 92 |
print_r("\ncreate multiple (array): \n\n");
|
| 93 |
print_r($createResult);
|
| 94 |
|
| 95 |
// query Contacts by name
|
| 96 |
$queryResult = $sfdc->query("select id, firstname, lastname from contact where firstname = 'TestFirstName'");
|
| 97 |
print_r("\nquery by name: \n\n");
|
| 98 |
print_r($queryResult);
|
| 99 |
|
| 100 |
// bulk delete Contacts by ID
|
| 101 |
$id1 = $queryResult['records'][0]->id;
|
| 102 |
$id2 = $queryResult['records'][1]->id;
|
| 103 |
$ids = array($id1, $id2);
|
| 104 |
$deleteResult = $sfdc->delete($ids);
|
| 105 |
print_r("\ndelete multiple ($id1 $id2): \n\n");
|
| 106 |
print_r($deleteResult);
|
| 107 |
|
| 108 |
// query Contacts by name (verify deleted)
|
| 109 |
$queryResult = $sfdc->query("select id, firstname, lastname from contact where firstname = 'TestFirstName'");
|
| 110 |
print_r("\nquery: (all deleted) \n\n");
|
| 111 |
print_r($queryResult);
|
| 112 |
|
| 113 |
// create lead
|
| 114 |
$lead = new sObject('Lead',
|
| 115 |
null,
|
| 116 |
array(
|
| 117 |
'Company' => 'TestCompany',
|
| 118 |
'FirstName' => 'TestFirstName',
|
| 119 |
'LastName' => 'TestLastName',
|
| 120 |
'Phone' => '555-555-1212',
|
| 121 |
'Fax' => '444-444-1212'
|
| 122 |
)
|
| 123 |
);
|
| 124 |
|
| 125 |
$useDefaultRule = new soapval('useDefaultRule', null, 'true');
|
| 126 |
$sfdc->setHeader('AssignmentRuleHeader', array($useDefaultRule));
|
| 127 |
|
| 128 |
$createResult = $sfdc->create($lead);
|
| 129 |
print_r("\ncreate lead: \n\n");
|
| 130 |
print_r($sfdc->client->request);
|
| 131 |
print_r($sfdc->client->response);
|
| 132 |
print_r($createResult);
|
| 133 |
|
| 134 |
$id = $createResult['id'];
|
| 135 |
|
| 136 |
// convert lead
|
| 137 |
$leadConvert = new LeadConvert(null, null, 'Qualified', false, $id, 'Converted Lead Opportunity', true, null, false);
|
| 138 |
$leadConvertResult = $sfdc->convertLead($leadConvert);
|
| 139 |
print_r("\nconvert lead: \n\n");
|
| 140 |
print_r($sfdc->client->request);
|
| 141 |
print_r($leadConvertResult);
|
| 142 |
|
| 143 |
print_r("\nsleeping for 60 seconds for updated and deleted examples\n\n");
|
| 144 |
sleep(60);
|
| 145 |
|
| 146 |
$endDate = $sfdc->getServerTimestamp();
|
| 147 |
|
| 148 |
// getUpdated
|
| 149 |
$getUpdatedResult = $sfdc->getUpdated("contact", $startDate, $endDate);
|
| 150 |
print_r("\ngetUpdatedResult (start: $startDate, end: $endDate)\n\n");
|
| 151 |
print_r($getUpdatedResult);
|
| 152 |
|
| 153 |
// getDeleted
|
| 154 |
$getDeletedResult = $sfdc->getDeleted("contact", $startDate, $endDate);
|
| 155 |
print_r("\ngetDeletedResult (start: $startDate, end: $endDate)\n\n");
|
| 156 |
print_r($getDeletedResult);
|
| 157 |
|
| 158 |
|
| 159 |
}
|
| 160 |
|
| 161 |
?>
|
| 162 |
|