matthewpoer/php-salesforce-wrapper

此包的最新版本(dev-master)没有可用的许可证信息。

某些常见 Lightning Platform REST API 函数的 PHP 包装器

dev-master 2020-05-02 01:41 UTC

This package is auto-updated.

Last update: 2024-09-29 04:49:47 UTC


README

使用 Pest 进行 REST

Pest 是一个用于 RESTful Web 服务的 PHP 客户端库。我发现它对这个项目来说是一个最小且有效的后端。Pest 依赖项由 composer 处理。

感谢 @Educoder!

Composer 安装

composer require matthewpoer/php-salesforce-wrapper:dev-master

开始使用

身份验证

在包装器实例化时进行 Salesforce 身份验证。

try {
  $sfdc = new php_sfdc_wrapper(
    SFDC_BASE_URL,
    SFDC_CLIENT_ID,
    SFDC_CLIENT_SECRET,
    SFDC_USERNAME,
    SFDC_PASSWORD,
    SFDC_SECURITY_TOKEN
  );
} catch (\Exception $e) {
  $log->critical('Error authenticating with Salesforce. Exception occurred.', array(
    'Exception' => $e->getMessage()
  ));
  die('Error authenticating with Salesforce. Exception occurred.' . PHP_EOL);
}

创建账户

try {
  $account_id = $sfdc->create('Account', array(
    'BillingCity' => 'San Francisco',
    'BillingCountry' => 'United States',
    'BillingPostalCode' => '94105',
    'BillingState' => 'California',
    'BillingStreet' => 'The Landmark @ One Market Suite 300',
    'Name' => 'Salesforce.com',
  ));
} catch (\Exception $e) {
  $message = $e->getMessage();
  $log->critical($message);
  die('Error creating Salesforce Account. Exception occurred.' . PHP_EOL);
}

删除账户

try {
  $account_id = $sfdc->delete('Account', $account_id);
} catch (\Exception $e) {
  $message = $e->getMessage();
  $log->critical($message);
  die('Error deleting Salesforce Account. Exception occurred.' . PHP_EOL);
}

按名称查找账户

查询方法接受以下参数:

  1. 一个对象名称
  2. 一个包含所需字段的数组,默认为仅包含 IdName 字段
  3. 用于 SOQL 查询的 WHERE 子句的字符串
  4. 一个布尔值,表示是否需要结果(默认为 TRUE)。如果这是 TRUE,则包装器将在找不到匹配 WHERE 子句中条件的记录时抛出异常。
try {
  $accounts = $sfdc->query(
    'Account',
    array('Id','Name'),
    "name='Salesforce.com'",
    FALSE
  );
  foreach($accounts as $account) {
    echo "Found account with ID of " . $account['Id'] . PHP_EOL;
  }
} catch (\Exception $e) {
  $message = $e->getMessage();
  $log->critical($message);
  die('Error querying for the Salesforce Account. Exception occurred.' . PHP_EOL);
}