codelicia / trineforce Goto Github PK
View Code? Open in Web Editor NEWA nice ✨ gambiarra ✨ to work with Salesforce SOQL Queries and Doctrine DBAL
License: MIT License
A nice ✨ gambiarra ✨ to work with Salesforce SOQL Queries and Doctrine DBAL
License: MIT License
I have been trying to use the examples to make my own queries but I haven't been able to use them verbatim.
If I try
$stmt = $this->connection->createQueryBuilder()
->select(['AccountId', 'Name'])
->from('Contact')
->where('AccountId = :id')
->setParameter('id', '0013Y00002ZZLOzQAP')
->setMaxResults(1);
I get the following invalid SOQL query
SELECT AccountId, Name FROM Contact WHERE AccountId = :'0013Y00002ZZLOzQAP' LIMIT 1
Notice the colon before the AccountId string.
To get a proper SOQL query I need to use ->setParameter(':id', '0013Y00002ZZLOzQAP')
with the colon.
Also trying to use positional parameters it seems like the index starts at 1 for positional parameter because of the use of
Doctrine\DBAL\Driver\OCI8\ConvertPositionalToNamedPlaceholders;
in the SoqlStatement class.
When I read the docs the positional parameters usually start at 0
but not for this driver.
https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/query-builder.html
Is there a reason why there is a custom logic in this driver around parameters?
I'm not proposing a change in the readme yet because first I want to clarify the reasoning behind the current code.
Congratulations on a great piece of software.
I would be great to define ORM objects that are configured to use this driver in the backend.
I have been researching this a bit and one of the initial obstacle is the lack of support for aliasing fields/columns in a SOQL query aka AS
.
Has anyone tried before?
I was very happy to find this library on packagist to develop a salesforce integration but before that I stumbled upon
https://github.com/Kephson/php-salesforce-rest-api
that is not a a DBAL
Trineforce fits more my project needs and I don't have to worry about sanitizing the parameters for the queries since that is done by doctrine.
I also discovered an eloquent model for salesforce
https://github.com/roblesterjr04/EloquentSalesForce
but I don't want to use laravel for this particular project.
My main goal is to make people aware of the alternatives so even if only the maintainer reads this issue is fine but I think it can be beneficial to have a little section in the readme that lists alternatives. I will propose the same on the other packages.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
composer.json
php ^8.1 || ^8.2
azjezz/psl ^2.7.0
doctrine/dbal ^3.6.6
doctrine/orm ^3.0.0
guzzlehttp/guzzle ^7.8.0
guzzlehttp/psr7 ^2.6.1
psr/http-message 2.0
doctrine/coding-standard ^12.0.0
infection/infection ^0.27.0
maglnet/composer-require-checker ^4.6.0
malukenho/mcbumpface ^1.2.0
phpunit/phpunit ^10.3.3
staabm/annotate-pull-request-from-checkstyle ^1.8.5
.github/workflows/ci.yml
actions/checkout v4
shivammathur/setup-php v2
.github/workflows/release-on-milestone-closed.yml
actions/checkout v4
laminas/automatic-releases v1
laminas/automatic-releases v1
ubuntu 22.04
As of today, we cannot consume a sObject
without doing a SOQL
query. But it still relevant to have a GET
request to specific resources, as SOQL
doesn't support *
when querying fields, and via direct resource consumption we can grab all data related to a resource.
The Hacky way to do it right now is to get the configured GuzzleHttpClient
and do the call directly.
$httpClient = $this->connection
->getWrappedConnection()
->getHttpClient();
$request = $httpClient->request(
'GET',
sprintf('/services/data/v40.0/sobjects/Opportunity/%s', $id)
);
Nowadays we don't treat cases of Request Throttling, which Salesforce sends to us out of the box in every REST response. We should be able to trigger specific exceptions for these cases of rate limit.
RequestThrottlingException
RequestThrottlingException::create()
RequestThrottlingException::copy()
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers_api_usage.htm
$result = $this->connection
->createQueryBuilder()
->select(['Id'])
->from('Account')
->join('Opportunities', ['Id'])
->where('ExternalId__c' = :externalId')
->setParameter('externalId', $externalId)
->execute()
->fetchAll();
var_dump($result);
This is the current result
array(1) {
[0]=>
array(2) {
["Id"]=>
string(18) "001w000001jEKBUMBA"
["Opportunities"]=>
NULL
}
}
To be able to use count
should be something like this
array(1) {
[0]=>
array(2) {
["Id"]=>
string(18) "001w000001jEKBUMBA"
["Opportunities"]=> []
}
}
When parameter contains url special character it's ignored in Soql:
`$phone = '+31612345678';
$sql = $conn->createQueryBuilder()
->select(['Contact.name','Contact.phone','Account.id', 'Account.name', 'Owner.email', 'Owner.name', 'Owner.id'])
->from('Contact')
->where('Phone = :phone')
->setParameter('phone', $phone, 'string')
->setMaxResults(1)
->execute();`
No results.
With urlencode in do_fetch
/** @return mixed[]|false */ private function doFetch() { // TODO: how to deal with different versions? Maybe
driverOptions`?
$request = $this->connection->get('/services/data/v20.0/query?q=' . urlencode($this->statement));
return json_decode($request->getBody()->getContents(), true);
}
`
One result
When clearing the cache of my app I get:
[info] User Deprecated: The "Doctrine\DBAL\Result::__construct()" method is considered internal The result can be only instantiated by {@see Connection} or {@see Statement}. It may change without further notice. You should not extend it from "Codelicia\Soql\DBAL\Result".
We have: private const SERVICE_COMPOSITE_URL = '/services/data/%s/composite';
But when used, "SERVICE_COMPOSITE_URL" is missing the tag replacement to have the API version actually inserted, which results in an invalid URL.
It would be helpful to have an extra optional parameter at the insert() method of ConnectionWrapper class, to pass an extra header when creating and object in Salesforce.
For example, to have Salesforce actually apply the defined assignment rules (which, sadly, it is not doing, although it is supposed to, by default) when creating a Case, we need to pass the following header: ['Sforce-Auto-Assign' => 'true']
The following code should work out of the box
$this->client
->createQueryBuilder()
->select([
'Id'
])
->from('Case')
->where('RecordType.Name IN (:recordTypeNames)')
->setParameter(
'recordTypeNames',
['a', 'b', 'third' => 'c'],
Types::TArray
)
->execute()
->fetch();
Currently, the version of the Salesforce REST API that will be used is hard coded. It would be valuable to be able to specify which version should be used.
For information, the list of available versions depends on the org, and can be retrieved from "https://yourInstance.salesforce.com/services/data/". At the time I'm writing, the latest seem to be v52.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.