Go Back   Mike Simonds > Salesforce > Salesforce Coding Discussions

This is a discussion on Salesforce Webservice methods and PHP within the Salesforce Coding Discussions forums, part of the Salesforce category; I'm trying to create an Apex class in Salesforce with a Webservice

Reply
 
LinkBack Thread Tools Rate Thread
  #1  
Old 05-03-2008, 05:48 PM
Junior Member
 
Join Date: May 2008
Posts: 7
Salesforce Webservice methods and PHP

I'm trying to create an Apex class in Salesforce with a Webservice method, then generate the WSDL for this class and call the Webservice method from PHP.

I have Apache, PHP5, the Salesforce PHP Toolkit and OpenSSL all installed, configured, and working.

I can use the PHP Toolkit to make SF API calls from my PHP scripts - that works great.

But I don't want to make those API calls from my PHP scripts - I want that code to run in the SF environment (my Webservice method), just pass in the parameters it needs and return data to the PHP.

However, I can't figure out how to login to SF and call my Webservice from PHP.

I know my Webservice method works - using a tool called soapUI, I load the WSDL for my class, set the headers, cut and paste the SessionID that's generated after logging into SF using the PHP Toolkit, run it, and it returns the value that it should from my Webservice method.

There is a thread in the SF Discussion Boards raising this issue here:

Community - Access APEX webservice from PHP - Perl, PHP, Python & Ruby Development - Salesforce.com Community

One of the posts includes a general description of a way they got it to work and an email address to request sample files of how they did it, but the person who posted it is out-of-office, and I'm hoping to find a solution ASAP.

Does anyone have any ideas? I'd appreciate any help.

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2  
Old 05-05-2008, 10:18 AM
Administrator
 
Join Date: May 2007
Posts: 214
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike

Matt

Thanks for joining the site. I just wanted to respond to your post and let you know that I am checking into this. I have never used this myself what so ever.

I did create a test APEX class in my development account to mess around with it and did notice that it creates a WSDL file? Is this the file that you are trying to access?

ALSO I read that thread you posted at the Salesforce Dev Forums and that email address that you received an out of office from. Is that a developer that has been able to access custom classes?


Are you just trying to pass data from Salesforce back to a PHP script on your server to process certain information. I am confused about this part of it:

Are you running a local process to run the APEX class to process data in your instance and then pass it back from Salesforce, using that class, and then return it to your server to process this custom script

Sorry for all the questions, just trying to get more of an idea on what you are trying to accomplish
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 05-05-2008, 02:43 PM
Junior Member
 
Join Date: May 2008
Posts: 7

Mike,

Thanks for taking a look at this, and thanks for setting up this site!

Yes, you create an Apex class that includes a Webservice function - when you view your list of Apex classes in SF->Setup->Develop->Apex Classes you see a link next to each Apex Class to generate the WSDL file for that class.

My understanding is that if you have a valid WSDL, you should be able to call functions in a webservice class over http via SOAP... which is what the PHP Toolkit does to make Apex calls, right? With the PHP Toolkit you instantiate a soap client, load the SF Partner WSDL, authenticate to SF, then make your Apex calls...

With the custom Apex Webservice class, the problem is that you have to authenticate to your salesforce environment first before you can make calls to the Webservice class. There doesn't seem to be a straightforward way to do this.

The developer who said he came up with a way to do it in the discussion boards did it by using the SF PHP Toolkit to authenticate to salesforce, grab that SessionId, then somehow use that SessionId in his calls to his Apex Webservice functions.

And I was able to do this using that soapUI tool. In a PHP script, I used the PHP Toolkit to log into salesforce to create the SessionId. I load the WSDL for my Apex class into the soapUI tool, then that tool let's me edit the header information of the request that's made to salesforce to access my Apex class, including a place to enter the SessionId in the header. I output the SessionId to the page created by my PHP, then copy/paste that SessionId into the header for the SOAP request in the soapUI tool. I run the soapUI tool and the response I get back shows that my Apex class runs and returns what it should.

So I need to figure out how to get this to work in PHP. I tried using a SOAP package for PHP called nusoap - you create a SOAP client and load the WSDL - just like the PHP Toolkit - and it lets you edit the header info, so I can insert the SessionId, but I'm not connecting with my Apex class in SF when I try this nusoap php package, like I can with the soapUI tool.

What I'm trying to do is:

I have a client who has a website that takes information from users on a form. We need to take that user information from the form and get it into salesforce - create contacts, or cases, or whatever.

I can do this using the PHP Toolkit from their web server, no problem. But I'll need to make multiple Insert/Upsert calls to their salesforce environment, and it seems to me that it would be better to have a webservice class set up in their SF environment where I can just pass in the user info from their website, and do all the Apex coding there and return some kind of success/error code, rather than doing multiple roundtrips from their web server to SF from the PHP script.

I hope that clears it up some - please ask if I it doesn't. I appreciate the help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 05-06-2008, 08:58 AM
Administrator
 
Join Date: May 2007
Posts: 214
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike

Wow that is a lot of information and I hope that you can get this done.

When I created the class in APEX yesterday (messing around), I did notice that it does create a WSDL file.

I am not sure how you would access it with the Toolkit, but if there is another developer that has done this (as you have stated).

Do you know how to capture the Session Id from Salesforce?

Is it just a form that you have? Does this form insert to contacts, Cases, or both? IS it a lead that you are creating?

Sorry for all the questions....

Try and email Nick Tran at Salesforce, he is the one that wrote the PHPToolKit

I will PM his email addy to you

~Mike

The NuSOAP wont work for this, it is too generic, The toolkit was written to replace that

ALSO

I don't/didn't know about the other class that you are using.

If I can get this figured out in the meantime, I will post it here

If you get it figured out, would you post your results here, it may help someone in the future
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 05-06-2008, 06:55 PM
Junior Member
 
Join Date: May 2008
Posts: 7

Here's how I get the SessionId using the Toolkit:

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

$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');

$mylogin = $mySforceConnection->login('salesforce-userid', 'password');

$sessionID = $mySforceConnection->getSessionId();

>>Is it just a form that you have? Does this form insert to contacts, >>Cases, or both? IS it a lead that you are creating?

It's a form that takes the user input and creates contacts and cases.


>>Try and email Nick Tran at Salesforce, he is the one that wrote the >>PHPToolKit
>>I will PM his email addy to you

That would be great if you could get me his E-mail! I'd love to see what his thoughts are on this.

If I find a solution I'll post it.

Thanks again!

-Matt
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 05-12-2008, 02:21 PM
Administrator
 
Join Date: May 2007
Posts: 214
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike

Matt

Sorry that I have not responded to this, I have been hammered at work

I will get to this ASAP and hopefully respond in the next 24 hours or so

~Mike
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7  
Old 05-13-2008, 08:56 AM
Administrator
 
Join Date: May 2007
Posts: 214
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike

Quote:
Originally Posted by Matt View Post
Here's how I get the SessionId using the Toolkit:

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

$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');

$mylogin = $mySforceConnection->login('salesforce-userid', 'password');

$sessionID = $mySforceConnection->getSessionId();

>>Is it just a form that you have? Does this form insert to contacts, >>Cases, or both? IS it a lead that you are creating?

It's a form that takes the user input and creates contacts and cases.


>>Try and email Nick Tran at Salesforce, he is the one that wrote the >>PHPToolKit
>>I will PM his email addy to you

That would be great if you could get me his E-mail! I'd love to see what his thoughts are on this.

If I find a solution I'll post it.

Thanks again!

-Matt
Matt maybe I am totally off base here but can't you capture the Salesforce session Id and copy it locally to a $_SESSION variable:

PHP Code:
<?php
session_start
();
require_once (
'./includes/sandbox_login.inc');

$_SESSION['my_session'] = $client->getSessionId();

echo 
$_SESSION['my_session'];

?>
output:

Code:
4e1300DR00000000XcD!ASAAQPQmK5pTjd8Sm4lDjerLqfIV61WNJ1BD.iQXTKSqdm13jZmuap0s_yeac_BKWXrI5kh.r4F0CPlqEfrIq_b2_kYYlIlo
then use it instead of copying and pasting it!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8  
Old 05-13-2008, 09:20 AM
Junior Member
 
Join Date: May 2008
Posts: 7

Mike,

Thanks again for looking at this -

I'm sorry, I don't think I'm being clear about this!

That is what I do - save the sessionID to a local var, it's the NEXT step that's the problem: Once I get the sessionID, how do I then call my custom salesforce Webservice methods?

-Matt
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9  
Old 05-13-2008, 09:21 AM
Administrator
 
Join Date: May 2007
Posts: 214
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike

Quote:
Originally Posted by Matt View Post
Mike,

Thanks again for looking at this -

I'm sorry, I don't think I'm being clear about this!

That is what I do - save the sessionID to a local var, it's the NEXT step that's the problem: Once I get the sessionID, how do I then call my custom salesforce Webservice methods?



-Matt
Ahh I see now, okay that clarifies it more..... Okay let me look into it more now
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10  
Old 05-13-2008, 09:24 AM
Administrator
 
Join Date: May 2007
Posts: 214
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike

Matt I just thought of this! Maybe your webservice method is in your Enterprise WSDL file? Have you generated one to take a look at it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
apex classes, generate wsdl file, salesforce, salesforce wsdl, webservice

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump



Powered by vBulletin


SEO by vBSEO 3.2.0 RC8 ©2008, Crawlability, Inc.

1 2 3 4 5