PHPackages                             stratease/salesforcery - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. stratease/salesforcery

ActiveLibrary[HTTP &amp; Networking](/categories/http)

stratease/salesforcery
======================

A PHP Salesforce ORM, inspired by Eloquent's API.

0.3.2(6y ago)69645Apache-2.0PHPPHP &gt;=5.6CI failing

Since Mar 8Pushed 6y ago1 watchersCompare

[ Source](https://github.com/stratease/salesforcery)[ Packagist](https://packagist.org/packages/stratease/salesforcery)[ Docs](https://github.com/stratease/salesforcery)[ RSS](/packages/stratease-salesforcery/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (2)Versions (7)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/f4778868cee3d8a3e22c2c66af360e4672215437c3f0ac475b1eeb61d6c9857e/68747470733a2f2f706f7365722e707567782e6f72672f7374726174656173652f73616c6573666f72636572792f762f737461626c65)](https://packagist.org/packages/stratease/salesforcery) [![Total Downloads](https://camo.githubusercontent.com/0f87fcb00be76ca14c1ec3e92d5aa6c1437be6c8fa4f88e8ef2f98efdf0aadbe/68747470733a2f2f706f7365722e707567782e6f72672f7374726174656173652f73616c6573666f72636572792f646f776e6c6f616473)](https://packagist.org/packages/stratease/salesforcery) [![License](https://camo.githubusercontent.com/f673af037c865dd434443904ac823802d951421b4c04a006e55abf3c1dd9be6a/68747470733a2f2f706f7365722e707567782e6f72672f7374726174656173652f73616c6573666f72636572792f6c6963656e7365)](https://packagist.org/packages/stratease/salesforcery)

A PHP ORM for Salesforce client applications, utilizing an OAuth2 REST client. Inspired by [Eloquent's](https://laravel.com/docs/master/eloquent) simple API.

Setup
=====

[](#setup)

### 1. Setting up a Connected App

[](#1-setting-up-a-connected-app)

You need to create a [Connected App](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_defining_remote_access_applications.htm) to generate the `client_id` and `client_secret` values for the OAuth2 connection. Once created use the credentials to register a connection.

### 2. Installation

[](#2-installation)

```
composer require stratease/salesforcery
```

### 3. Connection

[](#3-connection)

```
use Stratease\Salesforcery\Salesforce\Connection\REST\Authentication\PasswordAuthentication;
use Stratease\Salesforcery\Salesforce\Connection\REST\Client;
use Stratease\Salesforcery\Salesforce\Database\Model;

$authentication = new PasswordAuthentication([
     'grant_type' => 'password',
     'client_id' => 'your app ID',
     'client_secret' => 'your app secret',
     'username' => 'salesforce@user.com',
     'password' => 'password+token',
     'authorization_url' => 'https://test.salesforce.com/'
 ]);

// Typically https://login.salesforce.com, for testing use https://test.salesforce.com
$authentication->setEndpoint('https://test.salesforce.com/');

$client = new Client($authentication);
$response = $client->query("SELECT Id FROM Account LIMIT 1");

// Should output a response with a 'records' key that conains an array of results.
print_r($response);

// Register your connection so the ORM can connect
Model::registerConnection($client);

// Your model to connect to the Salesforce Account object
$account = Your/Models/Account::findOneBy('Id', 'abc123');

```

Examples
========

[](#examples)

### Defining a model

[](#defining-a-model)

For a simple setup...

```
use Stratease\Salesforcery\Salesforce\Database\Model;

class Account extends Model
{
    // Account maps to Account in Salesforce, nothing else required.
}
```

More advanced usage...

```
use Stratease\Salesforcery\Salesforce\Database\Model;

class Product extends Model
{
    public static $resourceName = 'Product2';
}
```

- Extend `Stratease\Salesforcery\Salesforce\Database\Model` and you're set! Sorta...
- The model's Salesforce Object name is mapped by default via the {ClassName} -&gt; {ObjectName}. You can override by defining the `resourceName` property.
- Explicit field definitions allowed with option to override. `get{Field}()`
- Will use `SchemaInspector` to discover fields for this resource and automatically hydrate instances with the fields

### Query Objects

[](#query-objects)

```
// Account is returned
$account = Account::findOneBy('Name', 'Acme Corp');
// An iterable Collection is returned
$accountCollection = Account::findBy(['OwnerId' => '123', 'Status' => 'Active']); // performs an AND expression on the associative array
foreach($accountCollection as $account) {
    echo "\n".$account->Name;
}
```

### Modify Objects

[](#modify-objects)

```
// create
$account = new Account();
$account->Name = 'Acme Uber Corp';
$account->save();

// update
$account2 = Account::findOneBy('Name', 'Acme Uber Corp');
$account2->Name = 'Acme Uber Inc.';
$account2->save();

// delete
$account2->delete();
```

Salesforce
==========

[](#salesforce)

This library uses Salesforces [REST API](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_list.htm). Tested on version 39.

Todo
====

[](#todo)

- Object relations mapping, i.e. `$contact->phone->isMobile`
- Add more REST endpoint support
- Batch REST integration
- Object -&gt; field schema cache. As it stands it will request the schema `n * Models` times per run. So if you do a series of requests utilizing `Account` and `User` models, it will request the schema twice, once for each model.
- Query builder object
- Look into extended Eloquent more formally.
- Test with other php versions. Was developed on `7.1`
- Docker environment for tests. As it stands now tests require a connection to a sandbox environment. Preferred setup for now in order to validate various Salesforce REST protocols are passing muster.
- Currently only support for OAuth2 `password` grant type. Accepting pull requests for other authorization protocols.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~120 days

Recently: every ~150 days

Total

6

Last Release

2386d ago

PHP version history (3 changes)0.1.1PHP 7.\*

0.3.1PHP ^5.6

0.3.2PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/d67af6523707f4b614c0a20762ceecf4deca64b0a6e83e0b4865bbfa8879e733?d=identicon)[stratease](/maintainers/stratease)

---

Top Contributors

[![stratease](https://avatars.githubusercontent.com/u/2826045?v=4)](https://github.com/stratease "stratease (5 commits)")

---

Tags

ormphpsalesforcesalesforce-rest-apiphpclientrestdatabaseormmodelsalesforce

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stratease-salesforcery/health.svg)

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

###  Alternatives

[nimbly/activeresource

Use a RESTful resource based API like a database

1043.5k](/packages/nimbly-activeresource)[wormling/phparia

Asterisk REST Interface (ARI) client for PHP.

419.8k](/packages/wormling-phparia)[rizeway/orem

Rizeway OREM is a Restful API Abstraction Layer. It is to Restful APIs what doctrine is for databases.

266.1k](/packages/rizeway-orem)

PHPackages © 2026

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