/**
  * @param      $sObjectType
  * @param      $id
  * @param bool $refresh
  *
  * @return array|bool|mixed|\Phpforce\SoapClient\Result\SObject[]|\Traversable|void
  */
 public function get($sObjectType, $id, $refresh = false)
 {
     $fields = false;
     $object = false;
     if (!$refresh) {
         $object = $this->memcached->get('salesforce.object.' . $id);
     }
     if (!$object) {
         // Get fields from memcache
         if (!$refresh) {
             $fields = $this->memcached->get('salesforce.objectFields.' . $sObjectType);
         }
         try {
             // If no data, ask Salesforce and save to memcached.
             if (!$fields) {
                 $obj = $this->soapClient->call('describeSObject', array('sObjectType' => $sObjectType));
                 $fields = array();
                 foreach ($obj->getFields() as $field) {
                     $fields[] = $field->getName();
                 }
                 $this->memcached->set('salesforce.objectFields.' . $sObjectType, $fields, $this->memcached_ttl);
             }
             // TODO: Log Salesforce Query and Result
             $object = $this->soapClient->retrieve($fields, array($id), $sObjectType);
             $object = $object[0];
             // Set Memcached
             $this->memcached->set('salesforce.object.' . $id, $object, $this->memcached_ttl);
         } catch (\Exception $e) {
         }
     }
     return $object;
 }
Exemple #2
0
 public function testQuery()
 {
     $soapClient = $this->getSoapClient(array('query'));
     $result = $this->getResultMock(new Result\QueryResult(), array('size' => 1, 'done' => true, 'records' => array((object) array('Id' => '001M0000008tWTFIA2', 'Name' => 'Company'))));
     $soapClient->expects($this->any())->method('query')->will($this->returnValue($result));
     $client = new Client($soapClient, 'username', 'password', 'token');
     $result = $client->query('Select Name from Account Limit 1');
     $this->assertInstanceOf('Phpforce\\SoapClient\\Result\\RecordIterator', $result);
     $this->assertEquals(1, $result->count());
 }
Exemple #3
0
 /**
  * Build the Salesforce SOAP client
  *
  * @return Client
  */
 public function build()
 {
     $soapClientFactory = new SoapClientFactory();
     $soapClient = $soapClientFactory->factory($this->wsdl, $this->soapOptions);
     $client = new Client($soapClient, $this->username, $this->password, $this->token);
     if ($this->log) {
         $logPlugin = new LogPlugin($this->log);
         $client->getEventDispatcher()->addSubscriber($logPlugin);
     }
     return $client;
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function queryAll($query)
 {
     $res = parent::queryAll($query);
     // TODO: Change the autogenerated stub
     $res->setSfToPhpConverter($this->getSfToPhpConverter());
     return $res;
 }
Exemple #5
0
 /**
  * @param string $method
  * @param array  $params
  *
  * @return array|\Traversable
  * @throws \Exception
  * @throws \SoapFault
  */
 public function call($method, array $params = array())
 {
     return parent::call($method, $params);
 }
Exemple #6
0
 /**
  * Query Salesforce for more records and rewind iterator
  *
  */
 protected function queryMore()
 {
     $result = $this->client->queryMore($this->queryResult->getQueryLocator());
     $this->setQueryResult($result);
     $this->rewind();
 }