function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JumpinjacqJumpinjacq 

public function createConnection() not working in salesforce connection

Hi there,

 

I need some help in figuring out where the issue is in this salesforce connection script, here is what I've got and done so far:

 

1.  I installed PHP Toolkit 20.0

2.  Downloaded enterprise wsdl and updated the file in toolkit under soapclient directory

3.  Updated security token to make sure it was accurate for the account I'll be creating a connection to

4.  Checked phpinfo() on my server to make sure all requirements were met (PHP Version 5.2.13, openssl enabled, SOAP Client and Server both enabled)

5.  Got the log in script uploaded to the server and ran it for the first time

6.  Fixed errors that I initially got related to paths and syntax

7.  Currently, the script works to $client = new SforceEnterpriseClient();, but the next line ($client->createConnection($wsdl);) is not executed properly, I think and although I've added error reporting in the script, I'm not getting any message other than the 500 internal server error as you'll see in point #9 and ultimately, I can't even confirm that I've actually connected to SF because the script is not getting that far

8.  I put in an echo statement right after $client = new SforceEnterpriseClient(); to make sure it was getting to that point, and that worked, because the screen output the message when the script was run;  I did the same after $client->createConnection($wsdl);, but the screen did not show the echoed message when the script was run

9.  If I do not have the echo statement after $client = new SforceEnterpriseClient();, I get a 500 internal server error on the screen when the script is run

 

The following is the log in script:

 

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
require_once ('lib/soapclient/SforceEnterpriseClient.php');
require_once ('lib/soapclient/SforceHeaderOptions.php');

// Login to salesforce.com
$login = 'my email for log in';
$password = 'my current pw that is confirmed correct';
$key = 'my updated token';

//join Password and Key here
$password = $password . $key;

$wsdl = 'lib/soapclient/enterprise.wsdl.xml';
$client = new SforceEnterpriseClient();
$client->createConnection($wsdl);

try
{
    $loginResult = $client->login($login, $password);

    if ($loginResult->passwordExpired)
    {
        unset($client);
    }
}
catch (exception $e)
{
    $error = '<pre>' . print_r($e, true) . '</pre>';
    mail('my email again', 'Salesforce Login Error', $error);
    unset($client);
}
?> 

 

 

I've exhausted any ideas for this issue, so I'm reaching out to anyone who might be able to help.  Thank you.

Best Answer chosen by Admin (Salesforce Developers) 
JumpinjacqJumpinjacq

Well, thanks so much for your time and effort Vishal, I really appreciate it.

 

I found the problem.  My WSDL file was not properly saved. As I compared the test WSDL and mine, I realized that there was something wrong. So I went back to the SF instructions on how to generate a WSDL:

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_quickstart_steps.htm#step_2_generate_or_obtain_the_web_service_wsdl

 

When I generated the WSDL, I copied and pasted the text on the page to my code editer and saved it as an .xml file...that was my mistake, I should have right clicked on my mouse and chose "Save page as", then saved it as an xml file.

 

Once I did this, I uploaded the new xml file to my server and the connection immediately succeeded.

 

I hope that my explanation was helpful.

All Answers

Vishal Gaddi6Vishal Gaddi6

<?php

session_start();

require_once ('soapclient/SforceEnterpriseClient.php');

require_once ('soapclient/SforceMetadataClient.php');// will be Used inCreating Custom Object and Custom Fields

 

define("USERNAME", "dummy@dummymail.com");

define("PASSWORD", "dummypass");

define("SECURITY_TOKEN", "9jjdudkdjkrRoBtFyiRduaDNC");// Replace ur Security Token

define("SF_NAMESPACE_PREFIX", getenv("?NAMESPACE_PREFIX"));

 

 try{

$mySforceConnection = new SforceEnterpriseClient();

$mySoapClient = $mySforceConnection->createConnection("enterprise.wsdl.xml");

$loginResult = $mySforceConnection->login(USERNAME,PASSWORD.SECURITY_TOKEN);

$myMetadataConnection = new SforceMetadataClient('metadata.wsdl.xml',$loginResult, $mySforceConnection);//Dont Use if you just need to connect

} catch (Exception $e) {

echo $myMetadataConnection->getLastRequest();

echo $e->faultstring;

// Now we can save the connection info for the next page

$_SESSION['location'] = $mySforceConnection->getLocation();

$_SESSION['sessionId'] = $mySforceConnection->getSessionId();

?>

 

This is working fine.... if you still get errors then i think you need to set ur Directory Structure....

JumpinjacqJumpinjacq

Thanks for your response Vishal,

 

I tried your code and I get the same 500 Internal Server Error, this is really bizarre.

 

When you say that I might have to set my directory structure, what did you mean?

 

J

Vishal Gaddi6Vishal Gaddi6

well...

 

simply put the connection file in the project folder, then copy the latest Soapclient folder into your project folder

 

hey copy your wsdl file into you project folder also... i thnk tht is creating problem in ur structure,,, 

JumpinjacqJumpinjacq

I'm sorry, I must be missing something really obvious, but please help me to understand.  My directory is set up like this:

 

subdomain for dev:

     lib:

          soapclient:

               ..

    connection file

    wsdl file

 

Is there a something that I've set up wrongly?  Please let me know.  Thanks.

 

 

Vishal Gaddi6Vishal Gaddi6

Hey

 

I think you should follow each step as mentioned in this artical.....

 

http://wiki.developerforce.com/page/Getting_Started_with_the_Force.com_Toolkit_for_PHP

 

Hope this is gona solve ur problem....

 

 If you still get same error, then you must check you installed webserver like WAMP,XAMPP or LAMP whichever you are using.....

 

JumpinjacqJumpinjacq

Hi Vishal,

 

I did as you suggested and reviewed every step of the instructions.  I just can't see where the problem is.

 

One thing I do know is that the code stops at this line in every version of the connection script that I have:

 

$mySoapClient = $mySforceConnection->createConnection("enterprise.wsdl.xml");

 

So in the folder /lib/soapclient/SforceBaseClient.php, the following function is not executing:

 

public function createConnection($wsdl, $proxy=null) {
		$phpversion = substr(phpversion(), 0, strpos(phpversion(), '-'));
		
		$soapClientArray = array (
			'user_agent' => 'salesforce-toolkit-php/'.$this->version,
			'encoding' => 'utf-8',
			'trace' => 1,
			'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
			'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP
		);

		// We don't need to parse out any subversion suffix - e.g. "-01" since
		// PHP type conversion will ignore it
		if (phpversion() < 5.2) {
			die("PHP versions older than 5.2 are no longer supported. Please upgrade!");
		}

		if ($proxy != null) {
            $proxySettings = array();
            $proxySettings['proxy_host'] = $proxy->host;
            $proxySettings['proxy_port'] = $proxy->port; // Use an integer, not a string
            $proxySettings['proxy_login'] = $proxy->login; 
            $proxySettings['proxy_password'] = $proxy->password;
            $soapClientArray = array_merge($soapClientArray, $proxySettings);
		}

		$this->sforce = new SoapClient($wsdl, $soapClientArray);
		return $this->sforce;
	}

 

If SOAP is enable on the server, what else could be the problem?

 

J

 

JumpinjacqJumpinjacq

Well, thanks so much for your time and effort Vishal, I really appreciate it.

 

I found the problem.  My WSDL file was not properly saved. As I compared the test WSDL and mine, I realized that there was something wrong. So I went back to the SF instructions on how to generate a WSDL:

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_quickstart_steps.htm#step_2_generate_or_obtain_the_web_service_wsdl

 

When I generated the WSDL, I copied and pasted the text on the page to my code editer and saved it as an .xml file...that was my mistake, I should have right clicked on my mouse and chose "Save page as", then saved it as an xml file.

 

Once I did this, I uploaded the new xml file to my server and the connection immediately succeeded.

 

I hope that my explanation was helpful.

This was selected as the best answer
Vishal Gaddi6Vishal Gaddi6

Cheers !!!