PHPackages                             codelicia/trineforce - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. codelicia/trineforce

ActiveLibrary[Database &amp; ORM](/categories/database)

codelicia/trineforce
====================

Salesforce Soql Doctrine Driver

1.2.1(3y ago)511.3k↓22.2%6[5 issues](https://github.com/codelicia/trineforce/issues)[7 PRs](https://github.com/codelicia/trineforce/pulls)MITPHPPHP ^8.1 || ^8.2CI passing

Since Sep 17Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/codelicia/trineforce)[ Packagist](https://packagist.org/packages/codelicia/trineforce)[ Docs](https://github.com/codelicia/)[ GitHub Sponsors](https://github.com/EHER)[ GitHub Sponsors](https://github.com/malukenho)[ RSS](/packages/codelicia-trineforce/feed)WikiDiscussions 2.x.x Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (41)Used By (0)

SOQL Doctrine DBAL
==================

[](#soql-doctrine-dbal)

**Salesforce Soql Doctrine Driver** allows you to write Soql queries and interact with a Salesforce instance using the Doctrine DBAL layer.

Now one can forget about Salesforce and have a nice `repository/query object`integration on one's architecture without hurting that much on the usual project structure.

### Installation

[](#installation)

Use `composer` to install this package as bellow:

```
$ composer require codelicia/trineforce
```

### Configuration

[](#configuration)

If you are familiar with Doctrine, then you probably already know how to configure and use it. But some special configuration is required in order to make it work.

When creating a new `Connection`, you should also provide the configuration keys for `salesforceInstance`, `consumerKey`, `consumerSecret` and point to the right `driverClass`. The usual `user` and `password` are also required.

```
$config = new Configuration();
$connectionParams = [
    'salesforceInstance' => 'https://[SALESFORCE INSTANCE].salesforce.com',
    'apiVersion'         => 'v43.0',
    'user'               => 'salesforce-user@email.com',
    'password'           => 'salesforce-password',
    'consumerKey'        => '...',
    'consumerSecret'     => '...',
    'driverClass'        => \Codelicia\Soql\SoqlDriver::class,
    'wrapperClass'       => \Codelicia\Soql\ConnectionWrapper::class,
];

/** @var \Codelicia\Soql\ConnectionWrapper $conn */
$conn = DriverManager::getConnection($connectionParams, $config);
```

- `user` provides the login, which is usually an email to access the salesforce instance.
- `password` provides the corresponding password to the email provided on `user`.
- `salesforceInstance` points to the url of the Salesforce instance.
- `apiVersion` specify a salesforce API version to work with.
- `consumerKey` provides the integration consumer key
- `consumerSecret` provides the integration consumer secret
- `driverClass` should points to `\Codelicia\Soql\SoqlDriver::class`
- `wrapperClass` should points to `\Codelicia\Soql\ConnectionWrapper::class`

By setting up the `wrapperClass`, we can make use of a proper `QueryBuild` that allow `JOIN` in the Salesforce format.

When using the doctrine bundle and the dbal is configured through yaml the options should be passed in a different way for the validation that the bundle does.

```
doctrine:
    dbal:
        driver: soql
        user: '%env(resolve:SALESFORCE_USERNAME)%'
        password: '%env(resolve:SALESFORCE_PASSWORD)%'
        driver_class: '\Codelicia\Soql\SoqlDriver'
        wrapper_class: '\Codelicia\Soql\ConnectionWrapper'
        options:
            salesforceInstance: '%env(resolve:SALESFORCE_ENDPOINT)%'
            apiVersion: v56.0
            consumerKey: '%env(resolve:SALESFORCE_CLIENT_ID)%'
            consumerSecret: '%env(resolve:SALESFORCE_CLIENT_SECRET)%'
```

### Using DBAL

[](#using-dbal)

Now that you have the connection set up, you can use Doctrine `QueryBuilder` to query some data as bellow:

```
$id = '0062X00000vLZDVQA4';

$sql = $conn->createQueryBuilder()
    ->select(['Id', 'Name', 'Status__c'])
    ->from('Opportunity')
    ->where('Id = :id')
    ->andWhere('Name = :name')
    ->setParameter('name', 'Pay as you go Opportunity')
    ->setParameter('id', $id)
    ->setMaxResults(1)
    ->execute();

var_dump($sql->fetchAll()); // All rest api result
```

or use the normal `Connection#query()` method.

### Basic Operations

[](#basic-operations)

Here are some examples of basic `CRUD` operations.

#### `Connection#insert()`

[](#connectioninsert)

Creating an `Account` with the `Name` of `John`:

```
$connection->insert('Account', ['Name' => 'John']);
```

#### `Connection#delete()`

[](#connectiondelete)

Deleting an `Account` with the `Id` = `1234`:

```
$connection->delete('Account', ['Id' => '1234']);
```

#### `Connection#update()`

[](#connectionupdate)

Update an `Account` with the `Name` of `Sr. John` where the `Id` is `1234`:

```
$connection->update('Account', ['Name' => 'Sr. John'], ['Id' => '1234']);
```

### Be Transactional with `Composite` API

[](#be-transactional-with-composite-api)

As salesforce released the `composite` api, it gave us the ability to simulate transactions as in a database. So, we can use the same Doctrine DBAL api that you already know to do transactional operations in your Salesforce instance.

```
$conn->beginTransaction();

$conn->insert('Account', ['Name' => 'John']);
$conn->insert('Account', ['Name' => 'Elsa']);

$conn->commit();
```

Or even, use the `Connection#transactional()` helper, as you prefer.

#### Referencing another Records

[](#referencing-another-records)

The `composite` api, also enables us to compose a structure data to be changed in one single request. So we can cross reference records as it fits our needs.

Let's see how to create an `Account` and a linked `Contact` to that `Account`in a single `composite` request.

```
$conn->transactional(static function () use ($conn) {

    $conn->insert('Account', ['Name' => 'John'], ['referenceId' => 'account']);
    $conn->insert('Contact', [
        'FirstName' => 'John',
        'LastName' => 'Contact',
        'AccountId' => '@{account.id}' // reference `Account` by its `referenceId`
    ]);

});
```

### 🚫 Known Limitations

[](#-known-limitations)

As of today, we cannot consume a `sObject` using the `queryBuilder` to get all fields from the `sObject`. That is because Salesforce doesn't accept `SELECT *` as a valid query.

The workaround that issue is to do a `GET` request to specific resources, then can grab all data related to that resource.

```
$this->connection
    ->getNativeConnection() // : \GuzzleHttp\ClientInterface
    ->request(
        'GET',
        sprintf('/services/data/v40.0/sobjects/Opportunity/%s', $id)
    )
    ->getBody()
    ->getContents()
;
```

### 📈 Diagram

[](#-diagram)

 ```
%%{init: {'sequence': { 'mirrorActors': false, 'rightAngles': true, 'messageAlign': 'center', 'actorFontSize': 20, 'actorFontWeight': 900, 'noteFontSize': 18, 'noteFontWeight': 600, 'messageFontSize': 20}}}%%
%%{init: {'theme': 'base', 'themeVariables': { 'actorBorder': '#D86613', 'activationBorderColor': '#232F3E', 'activationBkgColor': '#D86613','noteBorderColor': '#232F3E', 'signalColor': 'white', 'signalTextColor': 'gray', 'sequenceNumberColor': '#232F3E'}}}%%
sequenceDiagram
    autonumber
    Note left of ConnectionWrapper: Everything starts with the ConnectionWrapper.
    ConnectionWrapper->>QueryBuilder: createQueryBuilder()
    activate QueryBuilder
    alt
        QueryBuilder->>QueryBuilder: execute() Calls private executeQuery()method
    end
    QueryBuilder->>+ConnectionWrapper: executeQuery()
    deactivate QueryBuilder
    ConnectionWrapper->>SoqlStatement: execute()
    SoqlStatement->>+\Doctrine\DBAL\Driver\Result: execute()
    ConnectionWrapper->>+\Codelicia\Soql\DBAL\Result: new
    \Doctrine\DBAL\Driver\Result-->>\Codelicia\Soql\DBAL\Result: pass to
    \Codelicia\Soql\DBAL\Result-->>-ConnectionWrapper: returns
    ConnectionWrapper->>-SoqlStatement: fetchAll()
    SoqlStatement->>+\Codelicia\Soql\FetchDataUtility: fetchAll()
    \Codelicia\Soql\FetchDataUtility-->>+\GuzzleHttp\ClientInterface: send()
    Note right of \Codelicia\Soql\FetchDataUtility: Countable goes here? before creating the Payload?
    \Codelicia\Soql\FetchDataUtility->>+\Codelicia\Soql\Payload: new
    \Codelicia\Soql\Payload-->>+SoqlStatement: returns
```

      Loading ### Author

[](#author)

- Jefersson Nathan ([@malukenho](http://github.com/malukenho))
- Alexandre Eher ([@Eher](http://github.com/EHER))

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 72% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~72 days

Recently: every ~252 days

Total

29

Last Release

419d ago

Major Versions

0.4.x-dev → 1.0.02022-01-20

1.2.x-dev → 2.x-dev2025-03-25

PHP version history (5 changes)0.0.1PHP &gt;=7.2

0.0.9PHP &gt;=7.4

0.2.0PHP &gt;=7.4 || ~8.0

0.3.x-devPHP &gt;=8.1

1.2.1PHP ^8.1 || ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/1582e6b6023d34b69760da85219041ab8b376706b86ec03d942d12f946e4a7dc?d=identicon)[EHER](/maintainers/EHER)

![](https://www.gravatar.com/avatar/7140a8c7b834b07674c6bd74d6cb75792522ceba17dfb1f347489083a0ba1c48?d=identicon)[malukenho](/maintainers/malukenho)

---

Top Contributors

[![malukenho](https://avatars.githubusercontent.com/u/3275172?v=4)](https://github.com/malukenho "malukenho (152 commits)")[![EHER](https://avatars.githubusercontent.com/u/398034?v=4)](https://github.com/EHER "EHER (20 commits)")[![allcontributors[bot]](https://avatars.githubusercontent.com/in/23186?v=4)](https://github.com/allcontributors[bot] "allcontributors[bot] (14 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (9 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (9 commits)")[![rodrigoaguilera](https://avatars.githubusercontent.com/u/655187?v=4)](https://github.com/rodrigoaguilera "rodrigoaguilera (4 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

doctrinedoctrine-dbalsalesforcesalesforce-developers

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codelicia-trineforce/health.svg)

```
[![Health](https://phpackages.com/badges/codelicia-trineforce/health.svg)](https://phpackages.com/packages/codelicia-trineforce)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[kreait/firebase-php

Firebase Admin SDK

2.4k39.7M72](/packages/kreait-firebase-php)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58723.9M36](/packages/scienta-doctrine-json-functions)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4542.8M](/packages/damienharper-auditor-bundle)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
