function salesforce_api_demo in Salesforce Suite 7
Same name and namespace in other branches
- 5.2 salesforce_api/salesforce_api.module \salesforce_api_demo()
- 6.2 salesforce_api/salesforce_api.admin.inc \salesforce_api_demo()
- 7.2 salesforce_api/salesforce_api.admin.inc \salesforce_api_demo()
Demonstrates some of the API functionality through the Salesforce class and fieldmap functionality.
@todo 2/3 of the demo functionality is currently broken. see #692378
Parameters
$demo: The name of the demonstration to perform.
Return value
A string containing the page output.
See also
1 string reference to 'salesforce_api_demo'
- salesforce_api_menu in salesforce_api/
salesforce_api.module - Implements hook_menu().
File
- salesforce_api/
salesforce_api.admin.inc, line 654 - Contains the admin page callbacks for the Salesforce module, including forms for general settings and fieldmap administration.
Code
function salesforce_api_demo($demo = NULL, $arg = NULL) {
// Attempt to connect to Salesforce.
$sf = salesforce_api_connect();
// Display an error message if the connection failed.
if (!$sf) {
return t('Could not connect to Salesforce. Please doublecheck your API credentials.');
}
// Display the server timestamp first.
$response = $sf->client
->getServerTimestamp();
$output = '<p>' . t('<b>Salesforce server timestamp:</b> @timestamp', array(
'@timestamp' => $response->timestamp,
)) . '</p>';
// Add a specific demo's output.
switch ($demo) {
case 'data-structure':
if ($arg) {
$response = salesforce_api_describeSObjects(array(
check_plain($arg),
));
if (function_exists('dpm')) {
dpm($response);
}
elseif (function_exists('krumo')) {
$output .= krumo($response);
}
else {
$output .= '<pre>' . print_r($response, 1) . '</pre>';
}
}
else {
$response = salesforce_api_describeGlobal();
if (is_array($response->types)) {
foreach ($response->types as $type) {
if (is_object($type)) {
$items[] = l(t($type->label), SALESFORCE_PATH_DEMO . '/data-structure/' . $type->name);
}
elseif (is_string($type)) {
$items[] = l(t($type), SALESFORCE_PATH_DEMO . '/data-structure/' . $type);
}
elseif (is_array($type)) {
$items[] = l(t(current($type)), SALESFORCE_PATH_DEMO . '/data-structure/' . current($type));
}
}
$output .= theme('item_list', array(
'items' => $items,
'title' => t('Global Data Structure'),
));
}
}
break;
case 'user-export':
// TODO: This is broken. See http://drupal.org/node/692378
break;
global $user;
// Fully load the user account so we get profile data.
$account = user_load($user->uid);
// Create an object for export based on fieldmap 1.
$object = salesforce_api_fieldmap_export_create(1, $account);
$output .= t('Your user account prepared for export as a Contact based on <a href="!url">fieldmap 1</a>:', array(
'!url' => url(SALESFORCE_PATH_FIELDMAPS . '/1/edit'),
)) . '<pre>' . print_r($object, TRUE) . '</pre>';
// Export the object to Salesforce as a Contact.
$response = $sf->client
->create(array(
$object,
), 'Contact');
$output .= t('The response from Salesforce upon creation:') . '<pre>' . print_r($response, TRUE) . '</pre>';
break;
case 'campaign-export':
// TODO: Also broken. See http://drupal.org/node/692378
break;
// Load the campaign node.
$node = node_load(1);
// Create an object for export based on fieldmap 10.
$object = salesforce_api_fieldmap_export_create(10, $node);
$output .= t('Your campaign prepared for export as a Campaign based on <a href="!url">fieldmap 10</a>:', array(
'!url' => url(SALESFORCE_PATH_FIELDMAPS . '/10/edit'),
)) . '<pre>' . print_r($object, TRUE) . '</pre>';
// Export the object to Salesforce as a Contact.
$response = $sf->client
->create(array(
$object,
), 'Campaign');
$output .= t('The response from Salesforce upon creation:') . '<pre>' . print_r($response, TRUE) . '</pre>';
break;
}
$items = array(
l(t('Examine Data Structure'), SALESFORCE_PATH_DEMO . '/data-structure'),
);
$output .= '<p>' . t('<b>Choose from the following demonstrations:</b>') . theme('item_list', array(
'items' => $items,
)) . '</p>';
return $output;
}