shubinmi/salesforce-bulk-api
Composer 安装命令:
composer require shubinmi/salesforce-bulk-api
包简介
Client for Salesforce Bulk Api. Easy way to manipulate your Salesforce data.
关键字:
README 文档
README
Easy way to manipulate your Salesforce data
Don't worry, Be happy
Features
- INSERT job
- UPDATE job
- UPSERT job
- DELETE job
- QUERY (SELECT) job
For example see to the tests
Installation
Install the latest version with
$ composer require shubinmi/salesforce-bulk-api
Basic Usage
<?php use SalesforceBulkApi\dto\CreateJobDto; use SalesforceBulkApi\objects\SFBatchErrors; use SalesforceBulkApi\conf\LoginParams; use SalesforceBulkApi\services\JobSFApiService; // Set up API Client $params = (new LoginParams) ->setUserName('mySFLogin') ->setUserPass('MySFPass') ->setUserSecretToken('mySecretTokenFomSF'); // (optional) Flag as Sandbox // $params->setEndpointPrefixAsSandbox(); // Set up SF job $jobRequest = (new CreateJobDto) ->setObject('My_User__c') ->setOperation(CreateJobDto::OPERATION_INSERT); // Use CreateJobDto::OPERATION_UPSERT for upsert operation // (optional if Upsert) Set an External Id // $upsertKey = 'My_External_Id__c'; // $jobRequest->setExternalIdFieldName($upsertKey); // Data Batches $data = [ [ // Batch 1 [ 'Email__c' => 'new@user.net', 'First_Name__c' => 'New Net' ], [ 'Email__c' => 'new@user.org', 'First_Name__c' => 'New Org' ], ], [ // Batch 2 [ 'Email__c' => 'new1@user.net', 'First_Name__c' => 'New1 Net' ], [ 'Email__c' => 'new1@user.org', 'First_Name__c' => 'New1 Org' ], ], [ // Batch 3 [ 'Email__c' => 'new2@user.net', 'First_Name__c' => 'New2 Net' ], [ 'Email__c' => 'new2@user.org', 'First_Name__c' => 'New2 Org' ], ], ]; // Init Job $jobService = (new JobSFApiService($params)) ->initJob($jobRequest); // Add batches of data, can be up to 10000 records long each foreach ($data as $batchData) { $jobService->addBatchToJob($batchData); } // Gather up an ordered list of Batch ids to reference data in the batch, specifically on error handling // JobSFApiService::waitingForComplete update job statuses in the order returned from Salesforce // This new order is not necessarily the same order the data was submitted in making referencing the original data difficult $job = $jobService->getJob(); $batchesInfo = $job->getBatchesInfo(); $batchIdReference = array_flip(array_map(function($batchInfoDto){ return $batchInfoDto->getId(); }, $batchesInfo)); // Close Job and Wait for Job completion $jobService ->closeJob() ->waitingForComplete(); // Collect jobs errors $errors = $jobService->getErrors(); // Operate with errors foreach ($errors as $error) { /** @var SFBatchErrors $error */ $errorsBatch = $error->getBatchInfo(); $batchId = $errorsBatch->getId(); $batchNo = $batchIdReference[$batchId]; $errorsMsg = $error->getErrorMessages(); $errorsElementNumber = $error->getErrorNumbers(); if (empty($errorsElementNumber)) { // No specific errors echo "Batch $batchId (#$batchNo) returned a general error" . PHP_EOL; echo "\tState: " . $errorsBatch->getState() . ' (' . $errorsBatch->getStateMessage() . ')' . PHP_EOL; echo "\tNote: An error here might mean the data types sent are incorrect (eg \"0\" vs 0/false)." . PHP_EOL; } else { echo "Batch $batchId (#$batchNo) failed for following rows:" . PHP_EOL; foreach ($errorsElementNumber as $errorMsgKey => $errorRowNumber) { echo "\tRow number = " . $errorRowNumber . " Error message = " . $errorsMsg[$errorMsgKey] . PHP_EOL; $record = $data[$batchNo][$errorRowNumber]; echo "\t\tEmail = " . $record['Email__c'] . PHP_EOL; echo "\t\tFirst Name = " . $record['First_Name__c'] . PHP_EOL; } } }
Contribute safely
$ sh ./vendor/phpunit/phpunit/phpunit ./tests/services
统计信息
- 总下载量: 60.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2017-03-06