160 likes | 277 Views
Presented by Byrne Reese Product Manager, TypePad – Six Apart Lead Developer – SOAP::Lite Project. sForce 2P out of 3P: Perl and PHP. Agenda. Take a closer look at the sForce Perl Project Introducing php_gen_proxy. Why SOAP::Lite?. Pro’s Simple API PERL’s utility goes way beyond the Web
E N D
Presented by Byrne Reese Product Manager, TypePad – Six ApartLead Developer – SOAP::Lite Project sForce 2P out of 3P: Perl and PHP
Agenda • Take a closer look at the sForce Perl Project • Introducing php_gen_proxy
Why SOAP::Lite? Pro’s • Simple API • PERL’s utility goes way beyond the Web • Ubiquity of Perl • Excellent developer support, and 3rd party tool set • SOAP over HTTP, FTP, Jabber, and more Con’s • Document-Literal Support in Beta
SOAP::Lite – A Quick Update • Current version: 0.65 Beta 2 • Changes in 0.65 • Document-literal support • DIME support • Much improved documentation • Enhanced attachment management • Many interoperability fixes
Perl: Salesforce Module • Originally written for last year's dreamForce conference • What has changed in 2004? • Support for all 4.0 operations (with 5.0 to come) • Added additional unit tests and code samples • Added much needed documentation
Perl: Installation • Install SOAP::Lite> perl –MCPAN –e ‘install SOAP::Lite’ • Download Salesforce-0.54.tar.gz fromhttp://majordojo.com/salesforce • Unpack Salesforce-0.54.tar.gz • Run the standard:> cd Salesforce-0.54> perl Makefile.PL> make> make test> make install
Perl: login • Session ID is automatically persisted for subsequent calls #!/usr/bin/perl use Salesforce; my $service = new Salesforce::SforceService; my $port = $service->get_port_binding('Soap'); $port->login('username' => ‘byrne@majordojo.com’, 'password' => ‘xxxxxxxxx’); print “My Session ID: “.$port->{'sessionId'}.”\n”;
Perl: query • Perform a Query… #!/usr/bin/perl use Salesforce; my $service = new Salesforce::SforceService; my $port = $service->get_port_binding('Soap'); $port->login('username' => ‘byrne@majordojo.com’, 'password' => ‘xxxxxxxxx’); $result = $port->query('query' => "select Id,Name from Account", 'limit' => 10);
Perl: query (cont.) • Parse the results #!/usr/bin/perl use Salesforce; ... $result = $port->query('query' => ‘SELECT Id,Name FROM Account’, 'limit' => 10); foreach my $elem ($result->valueof('//queryResponse/result/records')) { printf "%s, %s\n", $elem->{Id},$elem->{Name}; }
Perl: Additional Resources • Salesforce Module man page • Salesforce Perl Module Homehttp://majordojo.com/salesforce/ • SOAP::Lite HOWTOs & Solutionshttp://majordojo.com/soaplite/ • SOAP::Lite Project Homepagehttp://www.soaplite.com/ • O’Reilly’s Programming Web Services with Perl, Randy J. Ray and Paul Kulchenko
PHP: Why Pear SOAP? • PHP is tailored for the Web • Simpler syntax • WSDL Support
PHP: php_gen_proxy • What it does: • Generates PHP code stubs that work against any SFDC WSDL • Why use it? • Pear SOAP's gen_proxy.php tool does not generate the necessary bindings to send SOAP Headers • A bug in Pear SOAP prevents Header definitons from being read properly in WSDLs
PHP: Installation • Prerequisites: • Pear SOAP • PHP 4.3.4 or greater (compiled with –with-zlib and –with-curl flag) • Install required Pear Modules:> pear install -fa SOAP-0.8RC3
PHP: Installation (cont.) • Download php_gen_proxy-0.50.tar.gz (Windows Zip file also available) from:http://majordojo.com/salesforce • Unpack php_gen_proxy-0.50.tar.gz • Patch SOAP/WSDL> patch /usr/local/lib/php/SOAP/WSDL.php WSDL.patch • Generate Code Stubs:> php gen_sfdc_proxy.php <wsdl> • Code
PHP: Sample Code <?php require_once("SalesforceClient.php"); $client = new SalesforceClient(); $result = $client->login(“byrne@majordojo.com”,”xxxxxxx”); if (PEAR::isError($result)) { echo "Error: " . $result->getMessage() . "\n"; exit; } $result = $client->query("select Id,FirstName,LastName from Lead"); while (list($k1, $record) = each($result->records)) { printf("%s %s, %s\n",$record->{'Id'}[0], $record->{'LastName'},$record->{'FirstName'}); } ?>
PHP: Additional Resources • php_gen_proxy Homepagehttp://www.majordojo.com/salesforce/ • PHP Project Homepagehttp://www.php.net • Pear Networkhttp://pear.php.net • Pear SOAP Homehttp://pear.php.net/package/SOAP