sforce 2p out of 3p: perl and php

16
sForce 2P out of 3P: Perl and PHP Presented by Byrne Reese Product Manager, TypePad – Six Apart Lead Developer – SOAP::Lite Project

Upload: terrel

Post on 07-Jan-2016

29 views

Category:

Documents


2 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: sForce 2P out of 3P:  Perl and PHP

sForce 2P out of 3P:

Perl and PHPPresented by Byrne Reese

Product Manager, TypePad – Six ApartLead Developer – SOAP::Lite Project

Page 2: sForce 2P out of 3P:  Perl and PHP

Agenda

• Take a closer look at the sForce Perl Project

• Introducing php_gen_proxy

Page 3: sForce 2P out of 3P:  Perl and PHP

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 moreCon’s• Document-Literal Support in Beta

Page 4: sForce 2P out of 3P:  Perl and PHP

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

Page 5: sForce 2P out of 3P:  Perl and PHP

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

Page 6: sForce 2P out of 3P:  Perl and PHP

Perl: Installation

• Install SOAP::Lite> perl –MCPAN –e ‘install SOAP::Lite’

• Download Salesforce-0.54.tar.gz from http://majordojo.com/salesforce

• Unpack Salesforce-0.54.tar.gz• Run the standard:

> cd Salesforce-0.54> perl Makefile.PL> make> make test> make install

Page 7: sForce 2P out of 3P:  Perl and PHP

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' => ‘[email protected]’,

'password' => ‘xxxxxxxxx’);

print “My Session ID: “.$port->{'sessionId'}.”\n”;

Page 8: sForce 2P out of 3P:  Perl and PHP

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' => ‘[email protected]’,

'password' => ‘xxxxxxxxx’);

$result = $port->query('query' => "select Id,Name from Account",

'limit' => 10);

Page 9: sForce 2P out of 3P:  Perl and PHP

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};

}

Page 10: sForce 2P out of 3P:  Perl and PHP

Perl: Additional Resources• Salesforce Module man page• Salesforce Perl Module Home

http://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

Page 11: sForce 2P out of 3P:  Perl and PHP

PHP: Why Pear SOAP?

• PHP is tailored for the Web• Simpler syntax• WSDL Support

Page 12: sForce 2P out of 3P:  Perl and PHP

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

Page 13: sForce 2P out of 3P:  Perl and PHP

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

Page 14: sForce 2P out of 3P:  Perl and PHP

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

Page 15: sForce 2P out of 3P:  Perl and PHP

PHP: Sample Code

<?php

require_once("SalesforceClient.php");

$client = new SalesforceClient();

$result = $client->login(“[email protected]”,”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'});

}

?>

Page 16: sForce 2P out of 3P:  Perl and PHP

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