brightecapital / salesforce-orm
Salesforce ORM
This package's canonical repository appears to be gone and the package has been frozen as a result. Email us for help if needed.
Installs: 58 404
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 9
Forks: 7
Open Issues: 1
pkg:composer/brightecapital/salesforce-orm
Requires
- php: ^8.1||^7.0
- doctrine/annotations: ^1.6
- eventfarm/restforcephp: dev-master
- league/csv: 9.3
- psr/log: ^1.1
Requires (Dev)
- phpunit/phpunit: 9.6.x-dev
- dev-master
- 1.8.13
- 1.8.12
- 1.8.11
- 1.8.10
- 1.8.9
- 1.8.8
- 1.8.7
- 1.8.6
- 1.8.5
- 1.8.4
- 1.8.3
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.9
- 1.7.8
- 1.7.7
- 1.7.6
- 1.7.5
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.9
- 1.6.8
- 1.6.7
- 1.6.6
- 1.6.5
- 1.6.4
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.9
- 1.5.8
- 1.5.7
- 1.5.6
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.5
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2
- 1.1.2
- 1.1.1
- 1.1
- 1.0
- dev-feature/BH-6179
- dev-bugfix-BH-5623
- dev-release-bulk-api
- dev-feature-BH-4570
- dev-feature-BH-4624
- dev-feature-BH-4563
- dev-feature-BH-4550
- dev-feature/phpunit
This package is auto-updated.
Last update: 2024-09-11 04:18:03 UTC
README
Configuration
composer.json
"require": {
"brightecapital/salesforce-orm": "^1.4.2"
}
Run
composer require brightecapital/salesforce-orm
Sample code
EntityManager
$config = [
'clientId' => 'yourSalesforceClientId'
'clientSecret' => "yourSalesforceSecret"
'path' => 'yourSalesforcePath'
'username' => 'yourSalesforceUsername'
'password' => 'yourSalesforcePassword'
'apiVersion' => 'yourSalesforceApiVersion'
];
$conn = new \Salesforce\Client\Connection($config);
$entityManager = new \Salesforce\ORM\EntityManager($conn);
Repository
/* @var \Salesforce\ORM\Repository */ $accountRepository = $entityManager->getRepository(Account::class);
class AccountRepository extends Repository
{
protected $className = Account::class;
}
$accountRepository = new AccountRepository($entityManager);
Objects
/* @var Account $account */
$account = $entityManager->getRepository(Account::class)->find('0010p000002Wam9AAC');
$account = $accountRepository->find('0010p000002Wam9AAC');
$account = new Account();
Create|Update Object
$account = new Account();
$account->setName('Your Name);
$account->setWebsite('YourWebsite);
$accountRepository->save($account); // this will create a new Account entity
$account = $entityManager->getRepository(Account::class)->find('0010p000002Wam9AAC');
$account->setWebsite('YourWebsite);
$account->setName('YourName');
$accountRepository->save($account); // this will update a the current Account entity
Entity and Field
/**
* Salesforce Account
*
* @package Salesforce\Entity
* @SF\Object(name="Account")
*/
class Account extends Entity
{
/**
* @var string
* @SF\Field(name="Name", required=true)
*/
protected $name;
/**
* @var string
* @SF\Field(name="Website")
*/
protected $website;
}
- @SF\Object(name="Account"): indicate that this class is mapping to Salesforce Account object
- @SF\Field(name="Name") : indicate that the property is mapping to filed 'Name' in Salesforce Account object
Relations, Required, Validations
/**
* Salesforce Account
*
* @package Salesforce\Entity
* @SF\Object(name="Account")
*/
class Account extends Entity
{
/**
* @var string
* @SF\Field(name="Name", required=true)
*/
protected $name;
/**
* @var string
* @SF\Field(name="Website")
* @SF\Url(value=true)
*/
protected $website;
/**
* @var array
* @SF\OneToMany(name="Contacts", targetClass="App\Domain\Marketing\Salesforce\Entity\Contact", field="Id", targetField="AccountId", lazy=false)
*/
protected $contacts;
}
- @SF\OneToMany(name="Contacts", targetClass="App\Domain\Marketing\Salesforce\Entity\Contact", field="Id", targetField="AccountId", lazy=false): indicate that one Account has many Contact
- targetClass : the implemented class of Contact
- field: the field/column of Account object
- targetField: the field/column of the target Contact object
- lazy: if lazy = false, the repository will autoload list of Contact of the Account when you do (default = true)
$account = $accountRepository->find('0010p000002Wam9AAC');
- @SF\Required(value=true): indicate that this field is required. An exception will be thrown if this property is not set when saving the entity
- @SF\Url(value=true): indicate that this field is a url. An exception will be thrown if the value of this property is not an url
Available validations: Url, Email, Date
Find and Count
// Find Account by conditions, by default lazy loading = false (will load relations) $accounts = $accountRepo->findBy(['Company_Name__c = Adant Services Group Pty Ltd']); // Find all Account, by default lazy loading = true (will not load relations) $accounts = $accountRepo->findAll(); // Find total number of Account $count = $accountRepository->count();