Download the PHP package ahmedwaleed/soquel without Composer
On this page you can find all versions of the php package ahmedwaleed/soquel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ahmedwaleed/soquel
More information about ahmedwaleed/soquel
Files in ahmedwaleed/soquel
Package soquel
Short Description An ORM solution for Salesforce Object Query Language (SOQL)
License MIT
Homepage https://github.com/AhmadWaleed/soquel
Informations about the package soquel
Salesforce Object Query Language (SOQL) Package For Laravel
Laravel SOQL query builder provides a convenient, fluent interface to creating, updating, SOQL queries and fetching records from salesforce.
Requirements
- PHP >= 7.4
- Laravel >= 8
- omniphx/forrest >= 2.*
This Package uses omniphx/forrest package as salesforce client to fetch records from salesforce, please refer to package github page for installation and configuration guide.
Installation
You can install the package via composer:
Optionally, you can publish the config file of package.
Set following config with your salesforce credentials.
Update the storage type to Session
or Cache
, only these storage types are suppored at this time.
Basic Usage
The content of config file will be published at config/soquel.php
-
Retrieving All Rows From A Object
-
Where Clauses
-
Additional Where Clauses
-
Select Sub Query
-
Subquery Where Clauses
- Ordering & Limit
ORM Usage
Query Builder is good when you want full control over query, but it becomes cumbersome with a query where you need to select all the fields of an object or want to load child pr parent object rows. This package also provide object-relational-mapper (ORM) support that makes it easy and enjoyable to interact with soql.
Generate Object Classes
To get started, lets create an Object class which by default lives in app/Objects
directory and extend
the AhmadWaleed\Soquel\Object\BaseObject
class, but you can change the default directory in the configuration file.
You may use the make:object
artisan command to generate a new object class:
The above command will generate following class:
If you would like to generate a custom object class you may use the --type
or -t
option:
The above command will generate following class:
By default, the Id field of salesforce object will be retrieved, You can also define on the model what fields you want to bring back with each record.
By default, the Id filed is readonly, You can specify which fileds should be excluded while performing insert/update operation on model.
Retrieving Objects
Once you have created an object, you are ready to start retrieving data from salesforce, You can think of each object class as a powerful query builder allowing you to fluently query salesforce object data. The get method will retrieve all (limited to 2000 by salesforce) of the records from the associated object.
Building Queries
Each Object class serves as query builder you add additional constraints to queries and invoke the get method to retrieve the results:
Collections
As we have seen, Object method like get retrieve multiple records from the salesforce. However, these methods don't return a plain PHP array. Instead, an instance of Illuminate\Database\Eloquent\Collection is returned.
The Object class extends Laravel's base Illuminate\Support\Collection class, which provides a variety of helpful methods for interacting with data collections. For example, the reject method may be used to remove objects from a collection based on the results of an invoked closure
Relationships
Salesforce's objects are often related to one another. For example, a Account may have many Contacts, or an Contact could be related to the Account. SOQL ORM makes managing and working with these relationships easy, and supports parent and child relationships:
Defining Relationships
Relationships are defined as methods on your Object classes. Since relationships also serve as powerful query builders, defining relationships as methods provides powerful method chaining and querying capabilities. For example, we may chain additional query constraints on this contacts relationship:
But, before diving too deep into using relationships, let's learn how to define each type of relationship.
Child To Parent
A child-to-parent relationship is a very basic type of salesforce relationship. For example, a Contact object might be associated with one Account object. To define this relationship, we will place a account method on the Contact object. The account method should call the parentRelation method and return its result. The parentRelation method is available to your model via the object AhmadWaleed\Soquel\Object\BaseObject base class:
The first argument passed to the parentRelation method is the name of the related object class. Once the relationship is defined, we may retrieve the related record with following query:
Additionally, you can pass object type and relationship name in second and third argument to parentRelation method;
For custom objects orm assumes relationship name, For example for custom object Jobc the relationship name will be Jobr, But if you want to override the default convention you can pass relationship name as third argument.
Parent To Child
A parent-to-child relationship is used to define relationships where a single object is the parent to one or more child objects. For example, a account may have an infinite number of contacts. Like all other Salesforce relationships, parent-to-child relationships are defined by defining a method on your Object class:
The first argument passed to the childRelation method is the name of the related object class. Once the relationship is defined, we may retrieve the related records with following query:
Additionally, you can pass object type and relationship name in second and third argument to childRelation method;
For custom objects orm assumes relationship name, For example for custom object Attachmentc the relationship name will be Attachmentr, But if you want to override the default convention you can pass relationship name as third argument.
Inserting and Updating
-
Insert
-
Insert Collection
- Update
License
The MIT License (MIT). Please see License File for more information.