Git Product home page Git Product logo

force.com-toolkit-for-php's People

Contributors

craigmarvelley avatar dcarroll avatar elidemayo avatar hjensen avatar marijnkoesen avatar midnightlightning avatar sergoslav avatar svc-scm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

force.com-toolkit-for-php's Issues

Update unit test throws an exception and fails to update

I got this error and stack trace with a copy of the update sample. I confirmed that the unit test throws the same exception.

PHP Fatal error:  Uncaught SoapFault exception: [sf:INVALID_FIELD] INVALID_FIELD: No such column '' on entity 'Lead'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. in /mnt/iscsi/www/digitalstreetinc.com/dev/sfconnector/soapclient/SforceBaseClient.php:514
Stack trace:
#0 /mnt/iscsi/www/digitalstreetinc.com/dev/sfconnector/soapclient/SforceBaseClient.php(514): SoapClient->__call('update', Array)
#1 /mnt/iscsi/www/digitalstreetinc.com/dev/sfconnector/soapclient/SforceBaseClient.php(514): SforceSoapClient->update(Object(stdClass))
#2 /mnt/iscsi/www/digitalstreetinc.com/dev/sfconnector/soapclient/SforcePartnerClient.php(171): SforceBaseClient->_update(Object(stdClass))
#3 /mnt/iscsi/www/digitalstreetinc.com/dev/sfconnector/sfconnector.php(34): SforcePartnerClient->update(Array)
#4 /mnt/iscsi/www/digitalstreetinc.com/dev/sfconnector/transmit.php(37): SFConnector->test()
#5 {main}
  thrown in /mnt/iscsi/www/digitalstreetinc.com/dev/sfconnector/soapclient/SforceBaseClient.php on line 514

upsert for Enterprise Toolkit broken

the upsert call for the Enterprise Toolkit is still broken.

It should be something like the following:

  /**
* Creates new objects and updates existing objects; uses a custom field to
* determine the presence of existing objects. In most cases, we recommend
* that you use upsert instead of create because upsert is idempotent.
* Available in the API version 7.0 and later.
*
* @param string $ext_Id External Id
* @param array $sObjects Array of sObjects
* @param string $type The type of objects being upserted.
* @return UpsertResult
*/
  public function upsert($ext_Id, $sObjects, $type = 'Contact') {
    $arg = new stdClass;
    $arg->externalIDFieldName = new SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema');
    foreach ($sObjects as &$sObject) {
      $sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace);
    }
    $arg->sObjects = $sObjects;
    return parent::_upsert($arg);
  }

See https://github.com/messageagency/salesforce/blob/master/soapclient/SforceEnterpriseClient.php for an example.

Use of toolkit through ESB : invalid soap-header

We do our communication with Salesfore not directly, but through Enterprise Solution Bus. So we don't need to login anymore to salesforce, but just the API-request to the ESB who will do his communication with Salesforce. But the ESB needs a special soap-header.

<soapenv:Header>
    <ns1:header soapenv:actor=“http://schemas.xmlsoap.org/soap/actor/next” soapenv:mustUnderstand=“0” xmlns:ns1=“http://www.xxxx.com/xsd/esb/ESBCommonTypes”>
    <ns1:message_type>SF_ENTPRISE_Interface</ns1:message_type>
    <ns1:version>01.80</ns1:version>
    <ns1:source_entity>xxxx</ns1:source_entity>
    <ns1:source_application>xxx</ns1:source_application>
    <ns1:destination_entity>xxx</ns1:destination_entity>
    <ns1:destination_application>xxx</ns1:destination_application>
    <ns1:message_id></ns1:message_id></ns1:header>
</soapenv:Header>

So I try to modify SfBaseClient, the method

private function setHeaders($call=NULL) {
......

      $soapHeader=new SoapHeader('http://www.leaseplan.com/xsd/esb/ESBCommonTypes', 'header', array (
            'client'=> 'test',
            'defaultNamespace'=> 'test',
            'message_type' => 'xxxx',
            'version' => '01.80',
            'source_entity' => 'xxx',
            'source_application' => 'LNOTES',
            'destination_entity'=> 'xx',
            'destination_application'=> 'SFxxxBE'
        ));


        array_push($header_array, $soapHeader);

        $this->sforce->__setSoapHeaders($header_array);

But when doing this, I always get
Fatal error: SoapClient::__setSoapHeaders(): Invalid SOAP header in C:\var\sourceRepositories\salesforce\Force.com-Toolkit-for-PHP-master\soapclient\SforceBaseClient.php on line 337

How can I obtain this functionality

Warning during SforceEnterpriseClient instantiation

When I try to instantiate SforceEnterpriseClient the following message is displayed:

Methods with the same name as their class will not be constructors in a future version of PHP; SforceEnterpriseClient has a deprecated constructor 

Fields are not recognized

Hi, maybe I am doing something wrong. I have the following issue:

Using the Enterprise API the phptoolkit (13 and 20) does not recognize a certain field when trying to send an update to an opportunity record. Updates tried were either setting a value to a field or deleting the value in this field. Btw. it is a custom field ("ISR_Owner__c").

When I tested with a describe on the opportunity structure I found out that the output doesn't contain dozens of fields, including the above cusom field. We have 150 custom fields in opp.

When using the OSX SOQL-Explorer or the Objective-C Library zksforce everything works fine.
The login using phptoolkit works fine too.

Any ideas where to dig into?
Thanks
Thomas

I can haz release tag?

I notice there are no releases (tags) in the repo, even though some commits make mention of version numbers (e.g., v20.0). As an API consumer, I want to make my application depend on some kind of "latest stable release", but I don't see anything indicating there is such a thing. Is master just supposed to always be stable?

Mixed return data from calling upsert

The upsert documentation says:

The upsert call returns an array of UpsertResult objects

If I use the following code:

  $records = array();
  $records[0] = new stdClass();
  $records[0]->ExternalId__c = 3;
  $records[0]->LastName = 'Nelson';
  $records[0]->FirstName = 'Horatio';
  $records[1] = new stdClass();
  $records[1]->ExternalId__c = 4;
  $records[1]->LastName = 'Bees';
  $records[1]->FirstName = 'Burt';

  $response = $mySforceConnection->upsert('ExternalId__c', $records, 'Contact');
  print_r($response);

I get the following response:

Array
(
    [0] => stdClass Object
        (
            [created] =>
            [id] => 0033000000rCfLrAAK
            [success] => 1
        )

    [1] => stdClass Object
        (
            [created] =>
            [id] => 0033000000rCfL4AAK
            [success] => 1
        )

)

This is as I expect per the documentation. However, if I make the call with a single object to upsert:

  $records = array();
  $records[0] = new stdClass();
  $records[0]->ExternalId__c = 3;
  $records[0]->LastName = 'Nelson';
  $records[0]->FirstName = 'Horatio';

  $response = $mySforceConnection->upsert('ExternalId__c', $records, 'Contact');
  print_r($response);

I get the following response:

Array
(
    [created] =>
    [id] => 0033000000rCfLrAAK
    [success] => 1
)

This inconsistency makes it tricky to generalise code to handle both situations, and also implies an issue with the documentation (as the PHP SOAP driver's result is being handed directly back, so I presume this is how SalesForce expects the data to be returned).

Before digging any further, I'd appreciate your feedback on this behaviour, expected or otherwise.

Calling logout after unsuccessful login causes fatal error

If a call to login() does not succeed (security token was no longer valid), a subsequent call to logout causes a fatal error.

(Of course, the right thing to do, and a workaround, is to not call logout() if login() did not succeed, but having a library of code cause a fatal error and exit on the spot, rather than throw an exception, is not the proper thing to do, in my opinion.)

The fatal error is:

PHP Fatal error: SoapClient::__setSoapHeaders(): Invalid SOAP header in Force.com-Toolkit-for-PHP-master/soapclient/SforceBaseClient.php on line 326

which is :
$this->sforce->__setSoapHeaders($header_array);

where $header_array is:

Array(
[0] =>
)

on a call to logout() after a failed login()

Partner API results are incorrectly formatted for Query

Very similar to another issue entitled Partner API results are incorrectly formatted for search and queryAll , I am seeing the following record objects when running the sample querymore from the PHP toolkit wiki (code below the output)

stdClass Object
(
    [type] => Lead
    [Id] => Array
        (
            [0] => 00QE000000FoJ7NMAV
            [1] => 00QE000000FoJ7NMAV
        )

    [any] => <sf:Email>[email protected]</sf:Email>
)

Here is a fragment from the sample:

$mySforceConnection = new SforcePartnerClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
  $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);

  $query = 'SELECT Id, Email From Lead Limit 1';
  $options = new QueryOptions(200);
  $mySforceConnection->setQueryOptions($options);
  $response = $mySforceConnection->query($query);
  $queryResult = new QueryResult($response);
  !$done = false;

  echo "Size of records:  ".$queryResult->size."\n";;

  if ($queryResult->size > 0) {
    while (!$done) {
      foreach ($queryResult->records as $record) {
        print_r($record);
      }

Query : Throw Exception SoapFault Object ( [message:protected] => Element {}item invalid at this location

I am using enterprise and able to login using mySforceConnection->login method. But when try to execute query using query mySforceConnection->query i got below exception.

SoapFault Object ( [message:protected] => Element {}item invalid at this location [string:Exception:private] => [code:protected] => 0 [file:protected] => /payment/soapclient/SforceBaseClient.php [line:protected] => 808 [trace:Exception:private] => Array ( [0] => Array ( [file] => /payment/soapclient/SforceBaseClient.php [line] => 808 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => query [1] => Array ( [0] => Array ( [queryString] => Select Name, zqu__BillToContact__c, zqu__BillToContact__r.Email, Contact_Email__c From zqu__Quote__c ) ) ) ) [1] => Array ( [file] => /payment/soapclient/SforceBaseClient.php [line] => 808 [function] => query [class] => SforceSoapClient [type] => -> [args] => Array ( [0] => Array ( [queryString] => Select Name, zqu__BillToContact__c, zqu__BillToContact__r.Email, Contact_Email__c From zqu__Quote__c ) ) ) [2] => Array ( [file] => /payment/enterprise.php [line] => 24 [function] => query [class] => SforceBaseClient [type] => -> [args] => Array ( [0] => Select Name, zqu__BillToContact__c, zqu__BillToContact__r.Email, Contact_Email__c From zqu__Quote__c ) ) ) [previous:Exception:private] => [faultstring] => Element {}item invalid at this location [faultcode] => soapenv:Client )

Support for findDuplicates

Salesforce now has matching rules to determine duplicate entries. These rules are established within the product and could change from time to time. There's a new call, findDuplicates(), that can be used but isn't supported by this toolkit. Anyone know how to add support??

Could not connect to host

Hi, sometimes that I try to connect to Salesforce I have this error:
Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /Force/soapclient/SforceBaseClient.php:168 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'https://login.s...', '', 1, 0) #1 Force/soapclient/SforceBaseClient.php(168): SoapClient->__call('login', Array) #2 Force/soapclient/SforceBaseClient.php(168): SoapClient->login(Array) #3 /home/donahoy/public_html/sincroniza/sincroniza.php(12): SforceBaseClient->login('universe...', '...') #4 {main} thrown in /Force/soapclient/SforceBaseClient.php on line 168

"Creating default object from empty value" when querying multiple relations

When querying multiple relations the following PHP warning appears:

Warning:  Creating default object from empty value in developerforce/force.com-toolkit-for-php/soapclient/SforceBaseClient.php on line 1097

Add:

if (is_null($this->fields)) {
    $this->fields = new stdClass();
}

After:

if (sizeof($anArray) > 0) {

AccountContactRelation Not Accessable

$mySforceConnection->describeSObject('AccountContactRelation')
returns: Fatal error: Uncaught SoapFault exception: [sf:INVALID_TYPE] INVALID_TYPE: sObject type 'AccountContactRelation' is not supported.

Account Contact Relationships activated for org.

screen shot 2017-05-23 at 5 15 31 pm

Are there any workarounds?

Add support for multi-record mergeRequests

According to the documentation for merge
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_merge.htm
up to 200 merge requests can be issued in a single SOAP call.

However, both SforcePartnerClient::merge() and SforceEnterpriseClient::merge() only accept a single merge request object, rather than an array of merge requests, and the WSDL definition of merge() doesn't appear to support multiple mergeRequests.

Also, the sample code in merge documentation does not show any examples issuing multiple mergeRequests per SOAP call.
Am I reading the documentation wrong?

My attempt at a patch resulted in the following fatal error:
Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object hasn't 'masterRecord' property

How to setTimeout() for query?

Hi,
A query that usually takes 2 seconds, sometimes goes beyong the default 10 seconds.
Is there any way to increase timeout?
Please help

Thank you

Confirmation it works with php 7

Hi,

Can you please confirm that it works with php 7? I'm getting errors only when I run on a server with php7 and I'm wondering if it's me or the framework.

Thanks

Incredibly hard to find on Packagist

Because the word "Salesforce" does not appear in the repo name or short description for this, it is very hard to find in Packagist / Composer for anyone looking for "salesforce" libraries.

Still maintained?

I am a bit sad to have to keep asking this on projects I use, but looking at the lack of commits and the bit-rotting PRs is it time to move on to a fork?

Major update

Recently, I started using this library for a project and during development, I've found how badly outdated it is. It lacks modern development practices and contains several bugs. Even worse, it seems to be abandoned, with many open issues and pull requests not being addressed at all.

Given the scale of the damage 😉, I decided to roll out my own, rewritten almost from scratch (but still sharing some common public parts).

Here's my effort and progress: https://github.com/uuf6429/Force.com-Toolkit-for-PHP/tree/Major-refactor#forcecom-toolkit-for-php

I'd be more than happy to see this merged into mainline eventually. Until then, I'd gladly listen to feedback/ideas and accept contributions (make sure you sign the SF CLA first though).

Can't create Contact and Opportunity in the same create() call using Partner Client

According to docs, https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_create.htm , I should be able to create a Contact and Opportunity in a single create() call.

Instead, when I try to do so using the toolkit i get the following error:

PHP Fatal error: SOAP-ERROR: Encoding: object has no "'type' property" salesforce

Breaking the exact same set of objects into two separate create()s works as expected.
I've tried both with and without "fields" array.

php 5.5.26, API version 34.0

What other info can i provide to help debug?

Salesforce Query

I have follow the guides and I am trying to achieve a simple retrieve of info.

I execute this portion of code:

//Get all Opportunities
$query = "SELECT Name, CloseDate from Opportunity";
$response = $mySforceConnection->query($query);
$queryResult = new QueryResult($response);

foreach ($queryResult->records as $record) {
    print_r($record);
}

This query returns me on each $record a stdClass Object with the following fields:

stdClass Object
(
    [type] => Opportunity
    [Id] => 
    [any] => <sf:Name>United Oil Refinery Generators</sf:Name><sf:CloseDate>2012-06-05</sf:CloseDate>
)

My question is, why I am not getting the fields or the same structure that is described on this example: https://developer.salesforce.com/page/PHP_Toolkit_20.0_Query_Sample_(Partner)

Apply fix for fieldsToNull issue to upsert()

I noticed in SforceEnterpriseClient.php::update() there is a "FIX for fieldsToNull issue".

From
https://github.com/developerforce/Force.com-Toolkit-for-PHP/blob/master/soapclient/SforceEnterpriseClient.php

        // FIX for fieldsToNull issue (STEP #1)
        $xmlStr = '';
        if(isset($sObject->fieldsToNull) && is_array($sObject->fieldsToNull)) {
            foreach($sObject->fieldsToNull as $fieldToNull) {
                $xmlStr .= '' . $fieldToNull . '';
            }
        }
        // ------
        
        $sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace);
        
        // FIX for fieldsToNull issue (STEP #2)
        if($xmlStr != '') {
            $sObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY);
        }
        // ------

Would a similar fix work for upsert()?
If so, can we get that in ASAP?

Updating wdsl.xml file

I'm trying to update my enterprise.wdsl.xml file to include some new custom fields on the opportunity object. None of the new fields are being recognized even though i've updated the actual file.

Is there anything else that needs to be changed? I noticed that there's a reference to the API version number in both the SforceMetaDataClient.php and SforceBaseClient.php, but changing them to the current (33.0) version doesn't seem to solve my problem.

I'm still able to pull the default/older fields, but can't access my new custom ones.

(upd: solved) Old Bug: API Query "Only Returns Id" Not The Requested Fields (php)

Hi,
I am getting the same error that this guy had 10 years ago by querying to a custom object.
ref: https://developer.salesforce.com/forums/?id=906F00000008tQnIAI
Querying contacts works just fine.

I've also set this:
ini_set('soap.wsdl_cache_enabled', '0');

Update: Solved it by regenerating a new enterprise.wsdl by following these steps.
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_quickstart_steps_generate_wsdl.htm

QueryResult Object
(
    [queryLocator] => 
    [done] => 1
    [records] => Array
        (
            [0] => stdClass Object
                (
                    [Id] => a0037000003WH16AAG
                )

            [1] => stdClass Object
                (
                    [Id] => a0037000003WH17AAG
                )

            [2] => stdClass Object
                (
                    [Id] => a0037000003WH18AAG
                )

            [3] => stdClass Object
                (
                    [Id] => a0037000003WHXaAAO
                )

            [4] => stdClass Object
                (
                    [Id] => a0037000002iG3tAAE
                )

        )

    [size] => 5
    [pointer] => 0
    [sf:QueryResult:private] => SforceEnterpriseClient Object
        (
            [sforce:protected] => SoapClient Object
                (
                    [trace] => 1
                    [compression] => 32
                    [_encoding] => utf-8
                    [_features] => 1
                    [_user_agent] => salesforce-toolkit-php/27.0
                    [_soap_version] => 1
                    [sdl] => Resource id #154
                    [__last_request_headers] => POST /services/Soap/c/27.0/00D37000000KONo HTTP/1.1
Host: na31.salesforce.com
Connection: Keep-Alive
User-Agent: salesforce-toolkit-php/27.0
Accept-Encoding: gzip, deflate
Content-Type: text/xml; charset=utf-8

PHP 5.5.9 - Object Items as String

I have been running PHP Toolkit 20 for the longest time on PHP 5.3.8. I am in the process of migrating to a PHP 5.5.9 Server and am having big issues with the QueryResults.

============= START CODE =========== createConnection(SALESFORCE_WSDL); $mylogin = $mySforceConnection->login(SALESFORCE_USER, SALESFORCE_PASS . SALESFORCE_TOKEN); $query = "SELECT Id, Name, Account_Owner_Name__c, Membership_Owner_Name__c, Sales_Initiator_Name__c FROM Account LIMIT 1"; $options = new QueryOptions(200); $mySforceConnection->setQueryOptions($options); $response = $mySforceConnection->query($query); $queryResult = new QueryResult($response); !$done = false; echo "Size of records: ".$queryResult->size."\n
";; $i = 0; if ($queryResult->size > 0) { while (!$done) { foreach ($queryResult->records as $record) { // $namevalue = $record->fields->Name."\r\n"; var_dump($queryResult); ``` // REF 1: Line below works, but is putting all data in for string fields in record->any value. // echo "
" . $i . "--AccountID: " . $record->Id[0] . " AccountName: " . $record->any . "
"; // REF 2: Line below only returns record->Id value. Only if Id[0] and not ->Id as in old toolkit. ``` // echo "
" . $i . "--AccountID: " . $record->Id[0] . " AccountName: " . $record->fields->Name . " AccountOwner: " . $record->fields->Account_Owner_Name__c . " MembershipOwner: " . $record->fields->Membership_Owner_Name__c . " SalesInitiator: " . $record->fields->Sales_Initiator_Name__c . "
"; $i++; } if ($queryResult->done != true) { echo "****\* Get Next Chunk *****\n"; try { $response = $mySforceConnection->queryMore($queryResult->queryLocator); $queryResult = new QueryResult($response); } catch (Exception $e) { print_r($mySforceConnection->getLastRequest()); echo $e->faultstring; } } else { $done = true; } } } } catch (Exception $e) { print_r($mySforceConnection->getLastRequest()); echo $e->faultstring; } ?>

==============END CODE ==============

The Query: $query = "SELECT Id, Name, Account_Owner_Name__c, Membership_Owner_Name__c, Sales_Initiator_Name__c FROM Account LIMIT 1";

object(QueryResult)#41 (6) { ["queryLocator"]=> NULL ["done"]=> bool(true) ["records"]=> array(1) { [0]=> object(stdClass)#42 (3) { ["type"]=> string(7) "Account" ["Id"]=> array(2) { [0]=> string(18) "0015000000lBvMaAAK" [1]=> string(18) "0015000000lBvMaAAK" } ["any"]=> string(242) "Kvh Industries, Inc.Erik AbergKevin GrahamAdam Herbert" } } ["size"]=> int(1) ["pointer"]=> int(0) ["sf":"QueryResult":private]=> bool(false) }

My var_dump of the query returns all the fields from Name to Sales_Initiator_Name__c as a string that is concatenated. (EG. REF 1)
I would like to get REF 2 working, NULLs are returned for $record->fields->Sales_Initiator_Name__c
or $record->Sales_Initiator_Name__c

Any ideas on how to update the toolkit to work with PHP 5.5.9 or higher. The above functionality is working with no issues on PHP 5.3.8

Thanks,

Jason

toolkit license, GPL compatibility, and Drupal.org library whitelist

tl;dr:
can we distribute the toolkit under a GPL-compatible license?

This issue came about when the Drupal.org Library Packaging Whitelist project was formed. The project aims to ease integration with third party packages by allowing them to be included and distributed on drupal.org.

The catch is that, to be whitelisted, any third-party package must be licensed under a GPL-compatible scheme.

While the license in the toolkit appears to be GPL-compatible, it is an unnamed license (and therefore not listed on gnu.org) and has been rejected for whitelisting (see http://drupal.org/node/1404212 ).

What do you think about changing the toolkit license to a similar, explicitly GPL-compatible license, so that the package may be included on drupal.org?

This package is used in a number of Drupal projects, including Salesforce Sutie. As long as I'm maintainer of the Salesforce Suite, I'll take personal responsibility for keeping the drupal.org package in synch with the version on github.com

Provide clarification / standard method for escaping string for use in SOQL

Hi;

Hopefully I'm missing something here, however I've read through countless articles and not been able to find an answer to what I think is a rather basic question.

Consider the following code:

<?php
$client = new SforceEnterpriseClient();
$client->createConnection($this->wsdl);
$client->login($this->username, $this->password . $this->security_token);
$query = "SELECT Id
            FROM Contact
           WHERE Email = '$email'
        ORDER BY LastModifiedDate ASC";
$response = $client->query($query);

Assuming that $email is a user-supplied variable then it's clear that it should be escaped to prevent query-injection vulnerabilities. However - it's not clear from any of the documentation how that should be escaped.

This page looks the most promising:
https://developer.salesforce.com/page/Secure_Coding_SQL_Injection#SOQL_INJECTION_And_Force.com_APIs

However it basically says to use parameterizied prepared queries (Which aren't supported via the SOAP API), or PDO to escape the string (Which requires a database connection, and will escape only for the context of that particular database connection).

It doesn't help that none of the examples listed at https://developer.salesforce.com/page/Getting_Started_with_the_Force.com_Toolkit_for_PHP or https://developer.salesforce.com/page/Tksample.php include any dynamic variables, or any escaping.

Please can you clarify the escaping method that is required to escape data in SOQL strings?

Ideally this library should either:

a) Expose (and recommend the use of) a parameterized query method that handles escaping internally, e.g.

<?php
$query = "SELECT Id
                FROM Contact
               WHERE Email = :email
            ORDER BY LastModifiedDate ASC";
$response = $client->query($query, array(':email' => $email));

b) Provide a string escaping function so developers aren't encouraged to roll their own , e.g.

<?php
$email = $client->escapeString($email);
$query = "SELECT Id
            FROM Contact
           WHERE Email = $email
        ORDER BY LastModifiedDate ASC";
$response = $client->query($query);

Apologies if this is already covered somewhere - but as someone new to the SalesForce APIs it's not easy to find :)

Bulk API support?

Does this project support the bulk api? I expected to see a file named 'BulkApiClient.php' but I do not.

Any advice appreciated.

Adding Set Locale header

Why locale header is only restricted to describeSObject and describeSObjects method only?
(see more in line 298 of the file master/soapclient/SforceBaseClient.php)

There are other methods like describeDataCategoryGroups and/or describeDataCategoryGroupStructures that could require this method as well.

Regards

Email class name collision

The Email class is a very common class name and collides with a globally namespaced class in our app. It would be preferable to namespace (or rename to something other than just Email) as to avoid such collisions.

Hardcoded na7 in soapclient/metadata.wsdl.xml may cause issues after NA7 Split (6 Dec 2014)

I have been using salesforce php toolkit (v13_1 and v20_1) for few years. For creating custom buttons, I use soapclient/metadata.wsdl.xml

I just heard that Salesforce will perform NA7 Split in next few days (6 or 7 Dec 2014). So I was looking for hardcodes in my code, configs, database, etc. And I just saw that na7 is hardcoded in soapclient/metadata.wsdl.xml

$ cd phptoolkit-20_1/soapclient
$ grep na7 *.xml
metadata.wsdl.xml:   <soap:address location="https://na7-api.salesforce.com/services/Soap/m/27.0"/>

How will this affect me? What do I do?

OldValue and NewValue attributes do not show up in queries on CaseHistory

I am using the following query with the SforcePartnerClient:

SELECT Id, CaseId, Field, CreatedById, CreatedDate, IsDeleted, NewValue, OldValue FROM CaseHistory WHERE CaseId='SOME_VALID_CASE_ID' 

I get values for all the requested fields, except NewValue and OldValue - they are not in the response. Looking at the SOAP traffic, I do see the OldValue and NewValue fields on the wire.

PHP7 - Setup null values in upsert

When trying to setup null values in UPSERT, I get the following error from the API.
SOAP-ERROR: Encoding: Cannot find encoding

This is only happening on PHP7.

Does anyone know what is happening or how this could be fixed?

Thanks in advance,
Gabriel

Partner API results are incorrectly formatted for search and queryAll

The following sample code:

<?php
// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.com password

define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');
require_once (SOAP_CLIENT_BASEDIR.'/SforceHeaderOptions.php');

require_once ('../userAuth.php');

try {
  $mySforceConnection = new SforcePartnerClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
  $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);

  $search = 'FIND {415*} IN PHONE FIELDS '.
        'RETURNING CONTACT(ID, PHONE, FIRSTNAME, LASTNAME), '.
        'LEAD(ID, PHONE, FIRSTNAME, LASTNAME), '.
        'ACCOUNT(ID, PHONE, NAME)';
  $searchResult = $mySforceConnection->search($search);

  print_r($searchResult);
} catch (Exception $e) {
  print_r($mySforceConnection->getLastRequest());
  echo $e->faultstring;
}
?>

Produces output with strangely formatted results:

stdClass Object
(
    [searchRecords] => Array
        (
            [0] => stdClass Object
                (
                    [record] => stdClass Object
                        (
                            [type] => Contact
                            [Id] => Array
                                (
                                    [0] => 0035000000o1n2jAAA
                                    [1] => 0035000000o1n2jAAA
                                )
                            [any] => <sf:Phone>(415) 486-9969</sf:Phone><sf:FirstName>Mary</sf:FirstName><sf:LastName>Jones</sf:LastName>
                        )
                )

            [1] => stdClass Object
                (
                    [record] => stdClass Object
                        (
                            [type] => Contact
                            [Id] => Array
                                (
                                    [0] => 0035000000o1n2iAAA
                                    [1] => 0035000000o1n2iAAA
                                )
                            [any] => <sf:Phone>(415) 486-9969</sf:Phone><sf:FirstName>John</sf:FirstName><sf:LastName>Smith</sf:LastName>
                        )
                )

            [2] => stdClass Object
                (
                    [record] => stdClass Object
                        (
                            [type] => Account
                            [Id] => Array
                                (
                                    [0] => 0015000000VALE4AAP
                                    [1] => 0015000000VALE4AAP
                                )
                            [any] => <sf:Phone>(415) 901-7000</sf:Phone><sf:Name>sForce</sf:Name>
                        )
                )
        )
)

I think the response should look more like this, with a SearchResult object similar to QueryResults, unique Id fields, and 'fields' objects instead of 'any'. Certainly there should be no XML in the output!

SearchResult Object
(
    [done] => 1
    [records] => Array
        (
            [0] => stdClass Object
                (
                    [record] => stdClass Object
                        (
                            [type] => Contact
                            [fields] => stdClass Object
                                (
                                    [Phone] => (415) 486-9969
                                    [FirstName] => Mary
                                    [LastName] => Jones
                                )
                            [Id] => 0035000000o1n2jAAA
                        )
                )

            [1] => stdClass Object
                (
                    [record] => stdClass Object
                        (
                            [type] => Contact
                            [fields] => stdClass Object
                                (
                                    [Phone] => (415) 486-9969
                                    [FirstName] => John
                                    [LastName] => Smith
                                )
                            [Id] => 0035000000o1n2iAAA
                        )
                )

            [2] => stdClass Object
                (
                    [record] => stdClass Object
                        (
                            [type] => Account
                            [fields] => stdClass Object
                                (
                                    [Phone] => (415) 901-7000
                                    [Name] => sForce
                                )
                            [Id] => 0015000000VALE4AAP
                        )
                )
        )
)

SoapClient TLS

Does SforceBaseClient need to be updated in light of POODLE vulnerability and Salesforce dropping SSL support?

I cannot find any good resource on how to instantiate PHP SoapClient to use only TLS instead of SSL.

Query using GROUP BY returning non parsed data

Hi :)

I'm opening the issue as requested.

I was doing a query using GROUP BY and the result was a XML with namespace that can't be parsed.

Here is the query:

SELECT 
  Produto__r.Marca__r.Id,
  Produto__r.Marca__r.Name,
  Produto__r.Marca__c,
  Produto__r.Marca__r.Id_Box__c
FROM
  Veiculos__c
WHERE
  Ativo__c = true
GROUP BY
  Produto__r.Marca__r.Id,
  Produto__r.Marca__r.Name,
  Produto__r.Marca__c,
  Produto__r.Marca__r.Id_Box__c

The result:

[
  {
  Id: [
    "a02j00000046DZ7AAM",
    "a02j00000046DZ7AAM"
  ],
  any: "<sf:Name>Hyundai importados</sf:Name><sf:Marca__c>a02j00000046DZ7AAM</sf:Marca__c><sf:Id_Box__c>7</sf:Id_Box__c>"
  },
  {
  Id: [
    "a02j0000004kRhJAAU",
    "a02j0000004kRhJAAU"
  ],
  any: "<sf:Name>HB20</sf:Name><sf:Marca__c>a02j0000004kRhJAAU</sf:Marca__c><sf:Id_Box__c>5</sf:Id_Box__c>"
  }
]

I'm using a workaround for now, basically I'm removing the sf: namespace from the xml tags, adding the xml declaration with a root node and loading it as a xml string something like:

$result = $query->records;
$objects = [];

foreach($result as $obj) {
  $str = preg_replace('{sf:}', '', $obj->any);

  $xml = '<?xml version="1.0" encoding="UTF-8"?><obj>'.$str.'</obj>';

  $objects[] = simplexml_load_string($xml);
}

Best regards

Numerous code and doc issues

Hello,
I finally got around to updating our toolkit version as I got tired of the issues with the PHPDoc's of the old version I was using and wanted to get us up to date.

I see many of the issues have been fixed, but there are still glaring issues with the code that any good IDE identifies immediately!

There are a few methods like partner client sendSingleEmail that use uninitialized variables like so:

$arg->messages = $messages;

$arg was never created... And due to the questionable behavior of PHP, the code likely 'works', but is still wrong.

Many doc blocks also miss $ like so:

  • @param array sObjects Array of sObjects

So to clean up the code, please open the code base in an IDE and fix the issues inspections are alerting on where possible (Sadly the use of relying on SoapClient for Class generation is going to result in many unknown classes)

But overall glad to see the docs mostly right now.

Access Files module

Is there a way to access the new-ish Files module that replaced Notes & Attachments using the SOAP API? I cannot seem to find the module on the docs. Or is the change simply on the force.com side and backend is all the same, still using Attachment?

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.