function salesforce_contract_select in Salesforce Suite 5
Same name and namespace in other branches
- 5.2 includes/salesforce_api.inc \salesforce_contract_select()
retreive contract information from an account
File
- includes/
salesforce_api.inc, line 354 - integration of Drupal and Salesforce.com. Original author: Steve Mckenzie Current maintainer: Victor Kane
Code
function salesforce_contract_select($account = NULL, $params = array(), $defaults = true) {
$salesforce = salesforce();
$account = _salesforce_select_account($account);
$admin = user_access('administer salesforce');
// first we need to make sure we have an account_id to work with
if (!$account->salesforce['account_id']) {
$result = salesforce_account_select($account);
$account->salesforce['account_id'] = $result['AccountId'];
if (!$account->salesforce['account_id']) {
return array(
'error' => 'NO_ACCOUNT_ID_FOUND',
);
}
}
// merge default fields it required
if ($defaults) {
$default = array(
'Id',
'Status',
'ContractTerm',
'ContractNumber',
'ActivatedDate',
'StartDate',
'EndDate',
);
$params = array_merge($default, $params);
}
// query salesforce for contract ids that this user has
$result = $salesforce
->query("SELECT id FROM contract WHERE accountId = '" . $account->salesforce['account_id'] . "'");
if (is_array($result['records'])) {
foreach ($result['records'] as $row) {
$contracts[] = $salesforce
->retrieve('id', "contract", array(
$account->salesforce['account_id'],
$account->salesforce['account_id'],
));
}
}
else {
$contracts = $salesforce
->retrieve(implode(', ', $params), "contract", array(
$result['records']->id,
$result['records']->id,
));
}
return $contracts;
}