function sf_node_export in Salesforce Suite 5.2
Same name and namespace in other branches
- 6.2 sf_node/sf_node.module \sf_node_export()
Exports a node to Salesforce using the specified fieldmap and stores the ID of the Salesforce object for the node.
Parameters
$nid: The nid of the node to export.
$fieldmap: The index of the fieldmap to use to create the export object.
$sfid: The Salesforce ID of the object you want to update. If left NULL, a new object will be created at Salesforce.
Return value
TRUE or FALSE indicating the success of the operation.
1 call to sf_node_export()
- sf_node_salesforce_form_submit in sf_node/
sf_node.module
File
- sf_node/
sf_node.module, line 408 - Integrates the core node object and various node related modules with the SalesForce API.
Code
function sf_node_export($nid, $fieldmap, $sfid = NULL) {
// Attempt to connect to Salesforce.
$sf = salesforce_api_connect();
// Load the node.
$node = node_load($nid);
// Create an object for export based on the specified fieldmap.
$object = salesforce_api_fieldmap_export_create($fieldmap, $node);
// Load the fieldmap so we can get the object name.
$map = salesforce_api_fieldmap_load($fieldmap);
if (empty($sfid)) {
// Export the object to Salesforce.
$response = $sf->client
->create(array(
$object,
), $map['salesforce']);
}
else {
$object->Id = $sfid;
$response = $sf->client
->update(array(
$object,
), $map['salesforce']);
}
// If the export was successful...
if ($response->success) {
if (empty($sfid)) {
// Store the Salesforce ID for the node and return TRUE.
salesforce_api_id_save('node', $nid, $response->id, $fieldmap);
}
return TRUE;
}
else {
// Otherwise log the error and return FALSE.
drupal_set_message('<pre>' . print_r($response, TRUE) . '</pre>', 'error');
return FALSE;
}
}