#!/usr/bin/perl # # Salesforce.com and SOAP::Lite demonstration code # use CGI qw(:standard); use Salesforce; my %FIELDS = ( 'lead' => [ qw(Id Salutation FirstName LastName Company Title LeadSource Industry AnnualRevenue Phone MobilePhone Fax Email Website Status Rating Employees EmailOptOut Street City State Zip Country Description) ] ); my $DATATYPE = param('type') || 'lead'; my $LIMIT = param('per') || 10; my $ACTION = param('action') || 'list'; my $SESSION = cookie('sf_session'); my $service = new Salesforce::SforceService; my $port = $service->get_port_binding('Soap'); #print header(-type => 'text/html'); #foreach my $key (keys %ENV) { # print $key."=".$ENV{$key}."
"; #} #exit; if (param('submit') eq 'Change Columns') { my $cookie = cookie( -NAME => 'sf_columns', -VALUE => join(',',param('col'))); print header( -COOKIE => $cookie, -LOCATION => "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?action=list"); exit; } elsif (param('submit') eq 'Login') { my $result = $port->login('username' => param('username'), 'password' => param('password')); my $cookie = cookie( -NAME => 'sf_session', -VALUE => $port->{'sessionId'}); print header( -COOKIE => $cookie, -LOCATION => "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?action=list"); exit; } my $COLUMNS = cookie('sf_columns') || 'Id,FirstName,LastName'; $port->{'sessionId'} = $SESSION; print header( -TYPE => 'text/html' ); print_header(); if (!$SESSION) { login(); } else { &$ACTION; } print_footer(); sub login { print < Username:

Password:


END_HTML } sub chcol { print < END_HTML foreach my $col (@{$FIELDS{$DATATYPE}}) { print " $col
\n"; } print < END_HTML } sub list { print < Results per page:

END_HTML foreach my $col (split(',',$COLUMNS)) { print ""; } print ' '; my $query_str = "select $COLUMNS from $DATATYPE"; $result = $port->query('query' => $query_str, 'limit' => $LIMIT); if ($result->fault()) { print $result->faultstring(); print "
$query_str
" } else { my $i = 0; foreach my $elem ($result->valueof('//queryResponse/result/records')) { print ""; printf "",++$i; foreach my $col (split(',',$COLUMNS)) { printf "",$elem->{$col}; } print "\n"; } } print '
$col
%d.%s
'."\n"; print <
Change Columns
END_HTML } sub print_header { print < sforce SOAP::Lite Demonstration
  
 
            


END_HTML } sub print_footer { print <


END_HTML }