GithubHelp home page GithubHelp logo

herurahmat / salesforce-bulk-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shubinmi/salesforce-bulk-api

0.0 0.0 0.0 32 KB

Php client for REST Salesforce Bulk Api.

License: Other

PHP 100.00%

salesforce-bulk-api's Introduction

Client for Salesforce Bulk Api

Easy way to manipulate your Salesforce data

Don't worry, Be happy

Scrutinizer Code Quality Latest Stable Version Maintainability Open Source Love MIT Licence Build Status Codacy Badge

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');

// Set up Insert SF job
$jobRequest = (new CreateJobDto)
    ->setObject('My_User__c')
    ->setOperation(CreateJobDto::OPERATION_INSERT);

// Data for Insert to custom SF entity
$data1 = [
    [
        'Email__c' => '[email protected]',
        'First_Name__c' => 'New Net'
    ],
    [
        'Email__c' => '[email protected]',
        'First_Name__c' => 'New Org'
    ]
];
$data2 = [
    [
        'Email__c' => '[email protected]',
        'First_Name__c' => 'New1 Net'
    ],
    [
        'Email__c' => '[email protected]',
        'First_Name__c' => 'New1 Org'
    ]
];

// Init Insert job and pull data
$insertJob = (new JobSFApiService($params))
    ->initJob($jobRequest)
    ->addBatchToJob($data1)
    ->addBatchToJob($data2)
    ->closeJob();

// Set up params for Upsert SF job
$jobRequest
    ->setOperation(CreateJobDto::OPERATION_UPSERT)
    ->setExternalIdFieldName('Email__c');

// Do Upsert job
$upsertJob = new JobSFApiService($params);
$upsertJob->initJob($jobRequest);

$data = [
    [
        'Email__c' => '[email protected]',
        'First_Name__c' => 'Not new Net'
    ],
    [
        'Email__c' => '[email protected]',
        'First_Name__c' => 'New Com'
    ]
];
$upsertJob
    ->addBatchToJob($data)
    ->closeJob();

// Collect jobs errors
$errorsOnInsert = $insertJob->waitingForComplete()->getErrors();
$errorsOnUpsert = $upsertJob->waitingForComplete()->getErrors();

// Operate with errors
foreach ($errorsOnInsert as $error) {
    /** @var SFBatchErrors $error */
    $errorsBatch         = $error->getBatchInfo();
    $errorsMsg           = $error->getErrorMessages();
    $errorsElementNumber = $error->getErrorNumbers();
    if (empty($errorsElementNumber)) {
        echo 'Batch ' . $errorsBatch->getId() . ' return ' . $errorsBatch->getState() . PHP_EOL;
    } else {
        echo 'Batch ' . $errorsBatch->getId() . ' fail for next rows:' . PHP_EOL;
        foreach ($errorsElementNumber as $errorMsgKey => $errorRowNumber) {
            echo 'Row number = ' . $errorRowNumber 
                . ' Error message = ' . $errorsMsg[$errorMsgKey] . PHP_EOL;
        }
    }
}

Contribute safely

$ sh ./vendor/phpunit/phpunit/phpunit ./tests/services

salesforce-bulk-api's People

Contributors

herurahmat avatar kevinreeves avatar shubinmi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.