View source
<?php
require_once 'salesforce.php';
$username = 'steve@raincitystudios.com';
$password = 'l3tme1n';
$sfdc = new salesforce('partner.wsdl');
$loginResult = $sfdc
->login($username, $password);
$batchSize = new soapval('batchSize', null, 2);
$sfdc
->setHeader('QueryOptions', array(
$batchSize,
));
if (!$loginResult) {
print_r("\nfailed login: \n\n");
print_r($sfdc->result);
}
else {
$response = $sfdc
->getServerTimestamp();
print_r("\ngetServerTimestamp: \n\n");
print_r($response);
$startDate = $response;
$contact = new sObject('Contact', null, array(
'FirstName' => 'TestFirstName',
'LastName' => 'TestLastName',
'Phone' => '555-555-1212',
'Fax' => '444-444-1212',
));
$createResult = $sfdc
->create($contact);
print_r("\ncreate one: \n\n");
print_r($createResult);
$id = $createResult['id'];
$queryResult = $sfdc
->query("select id, firstname, lastname, phone, fax from contact where id = '{$id}'");
print_r("\nquery by id: \n\n");
print_r($queryResult);
$contact1 = new sObject('Contact', $id, array(
'FirstName' => 'TestFirstName',
'LastName' => 'TestLastNameUpdate',
), array(
'Phone',
'Fax',
));
$updateResult = $sfdc
->update($contact1);
print_r("\nupdate one: \n\n");
print_r($updateResult);
$queryResult = $sfdc
->query("select id, firstname, lastname, phone, fax from contact where id = '{$id}'");
print_r("\nquery by id: \n\n");
print_r($queryResult);
$retrieveResult = $sfdc
->retrieve("id, firstname, lastname", "contact", array(
$id,
$id,
));
print_r("\nretrieve: \n\n");
print_r($retrieveResult);
$deleteResult = $sfdc
->delete($createResult['id']);
$id = $deleteResult['id'];
print_r("\ndelete one ({$id}): \n\n");
print_r($deleteResult);
$contacts = array(
$contact,
$contact,
);
$createResult = $sfdc
->create($contacts);
print_r("\ncreate multiple (array): \n\n");
print_r($createResult);
$queryResult = $sfdc
->query("select id, firstname, lastname from contact where firstname = 'TestFirstName'");
print_r("\nquery by name: \n\n");
print_r($queryResult);
$id1 = $queryResult['records'][0]->id;
$id2 = $queryResult['records'][1]->id;
$ids = array(
$id1,
$id2,
);
$deleteResult = $sfdc
->delete($ids);
print_r("\ndelete multiple ({$id1} {$id2}): \n\n");
print_r($deleteResult);
$queryResult = $sfdc
->query("select id, firstname, lastname from contact where firstname = 'TestFirstName'");
print_r("\nquery: (all deleted) \n\n");
print_r($queryResult);
$lead = new sObject('Lead', null, array(
'Company' => 'TestCompany',
'FirstName' => 'TestFirstName',
'LastName' => 'TestLastName',
'Phone' => '555-555-1212',
'Fax' => '444-444-1212',
));
$useDefaultRule = new soapval('useDefaultRule', null, 'true');
$sfdc
->setHeader('AssignmentRuleHeader', array(
$useDefaultRule,
));
$createResult = $sfdc
->create($lead);
print_r("\ncreate lead: \n\n");
print_r($sfdc->client->request);
print_r($sfdc->client->response);
print_r($createResult);
$id = $createResult['id'];
$leadConvert = new LeadConvert(null, null, 'Qualified', false, $id, 'Converted Lead Opportunity', true, null, false);
$leadConvertResult = $sfdc
->convertLead($leadConvert);
print_r("\nconvert lead: \n\n");
print_r($sfdc->client->request);
print_r($leadConvertResult);
print_r("\nsleeping for 60 seconds for updated and deleted examples\n\n");
sleep(60);
$endDate = $sfdc
->getServerTimestamp();
$getUpdatedResult = $sfdc
->getUpdated("contact", $startDate, $endDate);
print_r("\ngetUpdatedResult (start: {$startDate}, end: {$endDate})\n\n");
print_r($getUpdatedResult);
$getDeletedResult = $sfdc
->getDeleted("contact", $startDate, $endDate);
print_r("\ngetDeletedResult (start: {$startDate}, end: {$endDate})\n\n");
print_r($getDeletedResult);
}
?>