GithubHelp home page GithubHelp logo

advisors-excel-llc / salesforce-rest-sdk Goto Github PK

View Code? Open in Web Editor NEW
21.0 21.0 34.0 279 KB

An SDK for the Salesforce Rest and Streaming (Bayeux) API

PHP 100.00%
bayeux cometd rest-api salesforce-developers salesforce-rest-api salesforce-streaming-api streaming-data

salesforce-rest-sdk's People

Contributors

bluedot74 avatar curiosity26 avatar nickalafrance avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

salesforce-rest-sdk's Issues

having trouble autoloading JMS package

Doctrine\Common\Annotations\AnnotationException::semanticalError("The annotation "@jms\Serializer\Annotation\ExclusionPolicy" in class AE\SalesforceRestSdk\Bayeux\Message does not exist, or could not be auto-loaded.")

This is the problem im facing while using this package. Im trying to implement in laraval. im trying to do pushTopic streaming from salesforce but for some reason it is not supporting.

Can't unsubscribe after subscribe.

How can I unsubscribe after subscribe.
The flow I want to implement is
I start subscribing of Salesforce Streaming API by cron job in morning.
And I want to stop subscribing of Salesforce Streaming API in evening.

But I can't unsubsubscribe if no events is receiving during that time.

Is there anyways for unsubscribing the channel?

Annotation error with Streaming API

It's giving this weird error with streaming api client. I have already included doctrine-autoload-annotation package which is mentioned in one of the issue

PHP Fatal error:  Uncaught Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The annotation "@JMS\Serializer\Annotation\PreSerialize" in method AE\SalesforceRestSdk\Bayeux\Message::preSerialize() does not exist, or could not be auto-loaded. in /home/kiran/web/my-vehicles/php/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:54
Stack trace:
#0 /home/kiran/web/my-vehicles/php/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(739): Doctrine\Common\Annotations\AnnotationException::semanticalError('The annotation ...')
#1 /home/kiran/web/my-vehicles/php/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(661): Doctrine\Common\Annotations\DocParser->Annotation()
#2 /home/kiran/web/my-vehicles/php/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(354): Doctrine\Common\Annotations\DocParser->Annotations()
#3 /home/kiran/web/my-vehicles/php/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader in /home/kiran/web/my-vehicles/php/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php on line 54

I am using slim framework and composer auto-loading is already there. May I require to use manually register loaders as shown in readme?
AnnotationRegistry::registerLoader(array($loader, "loadClass"));

registerLoader method is deprecated and will be removed in new versions, so a good solution is required.

Trouble with Replay Extension

For some reason ReplayExtension doesn't work at all for me on the channel. I can set it up at the client level and I properly receive all past events when I subscribe to the PushTopic but it doesn't work on the channel object.

I've used the hasExtension method before and after the addExtension on the channel and it seems ok, it's false before and true after.

Any idea of what I'm missing ?

By the way I also encounter the #74 issue.

For information I'm using laravel 7 and SF API V44.0.

How to use replayId from Streaming API

Hello,

I wish to use replayId from streaming API to get missing messages while listener was down. I found the following code
$replayExtension = new \AE\SalesforceRestSdk\Bayeux\Extension\ReplayExtension({replayId here});
$streamingClient->addExtension($replayExtension);
But I can't get how to tie this to $channel->subsribe code. Could you point me to some piece of code which uses replayId to get messages that was not processed during listener shutdown?

Thanks

Possible to return SF response when Persisting object?

If I persist a new SObject (e.g Contact) on SF using the persist() method of the Client, the default response is true on success. But what if SF is returning JSON (crm_id) on successful persist. Is it possible to retrieve this data in the response?

trouble with streaming client

when i try the demo code on my test environment,it throw:

In AnnotationException.php line 54:

  [Semantical Error] The annotation "@JMS\Serializer\Annotation\PreSerialize"
   in method AE\SalesforceRestSdk\Bayeux\Message::preSerialize() does not exi
  st, or could not be auto-loaded.

Topic-level Extensions for the Streaming API

Per PR #34, a difference in how the Java/Javascript clients connect with CometD and make use of Extensions is different than how this SDK handles extensions.

Currently, this SDK applies Extensions to the Streaming Client and all topic subscriptions share the extensions, which may not always be the best solution.

The suggestion is to modify the ChannelInterface and Channel to allow for extensions to subscribe to them and pass the ChannelInterface object into the Extension as a parameter for the extension to make use of in determining if the extension needs to modify the message, also provided.

Getting strange errors for all calls I make

Authentication works well, but as soon as I issue pretty much any command, I get below error.
For example:
$result = $sObjectClient->query("SELECT Id, Name FROM Account");

PHP Fatal error: Uncaught Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The annotation "@jms\Serializer\Annotation\Type" in property AE\SalesforceRestSdk\Model\Rest\QueryResult::$done does not exist, or could not be auto-loaded. in C:\Users\ilana\vendor\doctrine\annotations\lib\Doctrine\Common\Annotations\AnnotationException.php:54
Stack trace:
#0 C:\Users\ilana\vendor\doctrine\annotations\lib\Doctrine\Common\Annotations\DocParser.php(734): Doctrine\Common\Annotations\AnnotationException::semanticalError('The annotation ...')
#1 C:\Users\ilana\vendor\doctrine\annotations\lib\Doctrine\Common\Annotations\DocParser.php(663): Doctrine\Common\Annotations\DocParser->Annotation()
#2 C:\Users\ilana\vendor\doctrine\annotations\lib\Doctrine\Common\Annotations\DocParser.php(354): Doctrine\Common\Annotations\DocParser->Annotations()
#3 C:\Users\ilana\vendor\doctrine\annotations\lib\Doctrine\Common\Annotations\AnnotationReader.php(254): Doctrine\Common\Annotations\DocParser->parse('/**\n * @var...', 'property AE\ in C:\Users\ilana\vendor\doctrine\annotations\lib\Doctrine\Common\Annotations\AnnotationException.php on line 54

curl SSL certificate error

I have faced problem getting curl SSL certificate error CachedOAuthProvider and OAuthProvider when running from shell.
We should add options parameter for CachedOAuthProvider and OAuthProvider construct function.

Error: [GuzzleHttp\Exception\RequestException] cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) in \vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 201
#1 \vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(105): GuzzleHttp\Handler\CurlFactory::finishError()

Stack Trace:
#0 \vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(155): GuzzleHttp\Handler\CurlFactory::createRejection()
#1 \vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(105): GuzzleHttp\Handler\CurlFactory::finishError()
#2 \vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish()
#3 \vendor\guzzlehttp\guzzle\src\Handler\Proxy.php(28): GuzzleHttp\Handler\CurlHandler->__invoke()
#4 \vendor\guzzlehttp\guzzle\src\Handler\Proxy.php(51): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler{closure}()
#5 \vendor\guzzlehttp\guzzle\src\PrepareBodyMiddleware.php(66): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler{closure}()
#6 \vendor\guzzlehttp\guzzle\src\Middleware.php(29): GuzzleHttp\PrepareBodyMiddleware->__invoke()
#7 \vendor\guzzlehttp\guzzle\src\RedirectMiddleware.php(70): GuzzleHttp\Middleware::GuzzleHttp{closure}()
#8 \vendor\guzzlehttp\guzzle\src\Middleware.php(59): GuzzleHttp\RedirectMiddleware->__invoke()
#9 \vendor\guzzlehttp\guzzle\src\HandlerStack.php(71): GuzzleHttp\Middleware::GuzzleHttp{closure}()
#10 \vendor\guzzlehttp\guzzle\src\Client.php(351): GuzzleHttp\HandlerStack->__invoke()
#11 \vendor\guzzlehttp\guzzle\src\Client.php(162): GuzzleHttp\Client->transfer()
#12 \vendor\guzzlehttp\guzzle\src\Client.php(182): GuzzleHttp\Client->requestAsync()
#13 \vendor\guzzlehttp\guzzle\src\Client.php(95): GuzzleHttp\Client->request()
#14 \vendor\ae\salesforce-rest-sdk\src\AuthProvider\OAuthProvider.php(148): GuzzleHttp\Client->__call()
#15 \vendor\ae\salesforce-rest-sdk\src\Rest\Client.php(214): AE\SalesforceRestSdk\AuthProvider\OAuthProvider->authorize()
#16 \vendor\ae\salesforce-rest-sdk\src\Rest\Client.php(55): AE\SalesforceRestSdk\Rest\Client->createHttpClient()

PHP 8 support

Composer gives this error

- ae/salesforce-rest-sdk[2.0.0, v2.0.1] require php ^7.2 -> your php version (8.0.2) does not satisfy that requirement.

Issue regarding topic subscribing

Hi All,
I am using your "ae/salesforce-rest-sdk" library. Its awesome. Thanks for it.

However i am trying to do Streaming api using this. But i am getting error.

  1. I created a push topic in my org , called "InvoiceStatementUpdates".
  2. I followed the instructions given on readme
  3. When i run the code, it started listing
  4. Then i opened my salesforce org and push a event on this topic by creating one contact
  5. As soon as i created a contact my php page stopped and given below error.

( ! ) Fatal error: Uncaught TypeError: Argument 1 passed to {closure}() must implement interface AE\SalesforceRestSdk\Bayeux\ConsumerInterface, instance of AE\SalesforceRestSdk\Bayeux\Channel given in D:\wamp64\www\salesforce-rest\client.php on line 47
( ! ) TypeError: Argument 1 passed to {closure}() must implement interface AE\SalesforceRestSdk\Bayeux\ConsumerInterface, instance of AE\SalesforceRestSdk\Bayeux\Channel given in D:\wamp64\www\salesforce-rest\client.php on line 47

Please help me to solve this. I have attached my code as well as error screen.

<?php
use AE\SalesforceRestSdk\Bayeux\BayeuxClient;
use AE\SalesforceRestSdk\AuthProvider\OAuthProvider;
use AE\SalesforceRestSdk\Bayeux\Transport\LongPollingTransport;
use Doctrine\Common\Annotations\AnnotationRegistry;
use AE\SalesforceRestSdk\Bayeux\Consumer;
use AE\SalesforceRestSdk\Bayeux\ConsumerInterface;
use AE\SalesforceRestSdk\Bayeux\Message;
use AE\SalesforceRestSdk\Bayeux\Extension\ReplayExtension;
use AE\SalesforceRestSdk\Bayeux\Extension\CachedReplayExtension;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

$loader = require_once 'vendor/autoload.php';
AnnotationRegistry::registerLoader(array($loader, "loadClass"));


$client = new BayeuxClient(
      new LongPollingTransport(),
      new OAuthProvider(
     "xxxxxx",
      "yyyyyyy",
      "https://login.salesforce.com",
      "ttttt",
      "zzzzz"
  )
 );



/** @var BayeuxClient $client */

// Getting a channel tells the client you want to subscribe to a topic
$channel = $client->getChannel('/topic/InvoiceStatementUpdates');

// Give some durability to the messages on this channel by adding the ReplayExtension
$channel->addExtension(new ReplayExtension(ReplayExtension::REPLAY_SAVED));

// Using the CachedReplayExtension give greater durability in that it will remember the replay Id of the last
// message received and pick up where it left off, even if the process stops and restarts. If no messages for the
// channel topic have been received, it will use the value provided in the constructor.
// Again, Any Psr\Cache\CacheItemPoolInterface will do for the adapter parameter
$channel->addExtension(new CachedReplayExtension(new FilesystemAdapter(), CachedReplayExtension::REPLAY_SAVED));


// Register topic consumers prior to starting the client
$channel->subscribe(
    Consumer::create(function (ConsumerInterface $consumer, Message $message) {
        // This will be fired when the client receives a topic notification
        
        $payload = $message->getData();
        
        // The payload has information about the event that occurred
        $event = $payload->getEvent();
        
        echo $event->getType(); // "created", "updated", "undeleted", "deleted"
        echo $event->getCreatedDate()->format(\DATE_ISO8601); // outputs the datetime the event was created
        echo $event->getReplayId(); // This ia n ID used by the replay extension so it can pick up the feed where it left off
        
        $sobject = $payload->getSobject();
        
        echo $sobject->Id; // Get the Id
        echo $sobject->getFields(); // this outputs all the fields and their values that were in the create or update request
    })
);

// Start the client to begin receiving notifications;
$client->start();

?>

By the way, one more thing, i wanted to subscibe "Platform Events" as well. Will this is also same as subscribing "Topic" ?

Library license

Hi, really cool lib thanks! But as I see in composer.json it is under proprietary license. Are you going to make it MIT or similar free to use? Because, otherwise, It doesn't make sense to contribute to this lib.

Symfony 5 support

Hey there! Any chance that there could be support for "symfony/cache" and "symfony/expression-language" versions that are used in symfony 5? Or do you know of a way to allow composer to install the required versions in this package?

I currently get:

Restricting packages listed in "symfony/symfony" to "5.0.*"
Your requirements could not be resolved to an installable set of packages.

Problem 1
    - ae/salesforce-rest-sdk v1.3.8 requires symfony/cache ~3.4|~4.0 -> no matching package found.
    - ae/salesforce-rest-sdk v1.3.7 requires symfony/cache ~3.4|~4.0 -> no matching package found.
    - ae/salesforce-rest-sdk v1.3.6 requires symfony/cache ~3.4|~4.0 -> no matching package found.
    - ae/salesforce-rest-sdk v1.3.5 requires symfony/cache ~3.4|~4.0 -> no matching package found.
    - ae/salesforce-rest-sdk v1.3.4 requires symfony/cache ~3.4|~4.0 -> no matching package found.
    - ae/salesforce-rest-sdk v1.3.3 requires symfony/cache ~3.4|~4.0 -> no matching package found.
    - ae/salesforce-rest-sdk v1.3.2 requires symfony/cache ~3.4|~4.0 -> no matching package found.
    - ae/salesforce-rest-sdk v1.3.1 requires symfony/cache ~3.4|~4.0 -> no matching package found.
    - ae/salesforce-rest-sdk v1.3.0 requires symfony/cache ~3.4|~4.0 -> no matching package found.
    - Installation request for ae/salesforce-rest-sdk ^1.3 -> satisfiable by ae/salesforce-rest-sdk[v1.3.0, v1.3.1, v1.3.2, v1.3.3, v1.3.4, v1.3.5, v1.3.6, v1.3.7, v1.3.8].

Thanks for your time!

Runtime exception with Streaming API

Getting this weird runtime exception error after about 60 seconds ....

PHP Fatal error:  Uncaught RuntimeException: Error creating resource: [message] fopen(https://nettix--uat.my.salesforce.com/cometd/48.0/meta/connect): failed to open stream: HTTP request failed!
[file] /home/kiran/web/my-vehicles/php/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php
[line] 323 in /home/kiran/web/my-vehicles/php/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php:252
Stack trace:
#0 /home/kiran/web/my-vehicles/php/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(334): GuzzleHttp\Handler\StreamHandler->createResource(Object(Closure))
#1 /home/kiran/web/my-vehicles/php/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(51): GuzzleHttp\Handler\StreamHandler->createStream(Object(GuzzleHttp\Psr7\Request), Array)
#2 /home/kiran/web/my-vehicles/php/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(66): GuzzleHttp\Handler\StreamHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#3 /home/kiran/web/my-vehicles/php/vendor/guzzlehttp/guzzle/src/Middleware.php(36): GuzzleHttp\PrepareBodyMiddlew in /home/kiran/web/my-vehicles/php/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 52

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.