function sf_user_export in Salesforce Suite 5.2
Same name and namespace in other branches
- 6.2 sf_user/sf_user.module \sf_user_export()
Exports a user to Salesforce using the specified fieldmap and stores the ID of the Salesforce object for the user.
Parameters
$uid: The uid of the user 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_user_export()
- sf_user_salesforce_form_submit in sf_user/
sf_user.module
File
- sf_user/
sf_user.module, line 325 - Integrates the core user object and profile module with the Salesforce API.
Code
function sf_user_export($uid, $fieldmap, $sfid = NULL) {
// Attempt to connect to Salesforce.
$sf = salesforce_api_connect();
// Load the user.
$account = user_load(array(
'uid' => $uid,
));
// Create an object for export based on the specified fieldmap.
$object = salesforce_api_fieldmap_export_create($fieldmap, $account);
// 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('user', $uid, $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;
}
}