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
rjkrjk 

New Perl implementation: Sforce::Sfdc

I have packaged up version 0.03 of my new Perl implementation for Sforce, which I have named Sforce::Sfdc. My company is releasing this code as free software under the LGPL.

Sforce::Sfdc inherits from XMLRPC::Lite, and was based on the code posted here by Ron Hess. It is object-oriented and should be both platform-independent and interface-independent.


http://www.focalex.com/sforce/Sforce-Sfdc-0.03.tar.gz


Please download the module, check it out, and give me feedback. I'm especially looking for feedback on the following issues:

1) The name of the module. Maybe it should be XML::Sforce, or Sforce::XMLRPC, or...

2) Anything I did that is bad practice in terms of XML and XML-RPC. I have very little experience in that area.

3) The interface for the helper methods, e.g. login(username => $username, password => $password). Should I just make that login($username, $password)? What about the more complicated methods, such as query()?

4) Bugs, of course.

5) Features that would be useful to have.


I'll post the current documentation as a reply to this message.


enjoy!
Ronald
rjkrjk

NAME
Sforce::Sfdc - Access sforce via XML

SYNOPSIS
use Sforce::Sfdc;

$sfdc = new Sforce::Sfdc (secure_mode => 1, autotype_as_described => 1);

$sfdc->login(username => 'bob@example.com', password => 'mypasswd');

$result = $sfdc->describe(type => 'global');

$result = $sfdc->describe(type => 'account');

$result = $sfdc->insert(type => 'account', record => \%record);

$result = $sfdc->update(type => 'account', record => \%record);

$result = $sfdc->query(type => 'account', scope => 'filter',
select => \@field_names, filter => \@filters);

$sfdc->logout();

DESCRIPTION
Sforce::Sfdc provides a Perl interface to sforce, the
client/server application platform for salesforce.com,
implementing version 2.0 of the sforce API. Sforce::Sfdc
inherits from XMLRPC::Lite.

OPTIONS

These options may be set when creating a new Sforce::Sfdc
object. Certain options may also be set later, by using
the object as a hash reference, e.g.
"$sfdc->{'retry_limit'} = 5".

secure_mode
If secure_mode is true, login() will open a secure
connection to sforce via SSL; otherwise a normal non-
secure connection is opened. Changing secure_mode
after login() has been called will not affect the con-
nection.

secure_mode defaults to true.

autotype_as_described
autotype_as_described provides a more accurate system
of autotyping than the normal regular expression
matching. If autotype_as_described is true, then
Sforce::Sfdc will set the type of each field value
based on the actual description of that field in
sforce. Before calling the method in which the auto-
typing is to occur, you must first call describe() on
the appropriate entity type, which caches the field
descriptions for that entity type in the Sforce::Sfdc
object.

autotype_as_described is supported in the following
methods: insert(), update(), query(), batch(). auto-
type_as_described is not supported in calls made
directly to call().

$sfdc->describe(type => 'account');
$sfdc->insert(type => 'account',
record => { name => 'My Company',
accountNumber => '137946',
type => 'client',
industry => 'marketing',
sales => 100_000,
...
}
);

In the above example, without autotype_as_described
the value of 100000 for sales would be passed to
sforce as an int. This would cause an error, because
sforce is expecting a double. With auto-
type_as_described, the value will be correctly passed
as a double.

autotype_as_described defaults to false.

retry_limit
Sforce imposes a rate limit on requests; when the rate
limit is exceeded, Sforce returns a retry response
indicating the number of milliseconds to sleep before
trying again. retry_limit specifies the maximum num-
ber of times to retry a call in this situation. If
the retry_limit is exceeded, the method sets
$Sforce::Sfdc::errstr and returns false.

retry_limit defaults to 10.

METHODS


new
my $sfdc = new Sforce::Sfdc (secure_mode => 1,
autotype_as_described => 1);

Creates a new Sforce::Sfdc object. After creating the
object, login() must be called to establish an actual
connection to sforce.

See "OPTIONS" for a description of the options when
creating a new object.

errstr
die $sfdc->errstr();

Returns the contents of $Sforce::Sfdc::errstr.

type
$sfdc->type(double => 7);
Sforce::Sfdc::type(string => '02458');

Calls SOAP:ata::type to cast a value as a specific
type. Use this when the autotyping would choose the
wrong type.

The following methods are wrappers around the sfdc calls
of the same name. Although sforce calls can be made using
the call() method, using the specific wrapper methods such
as describe() and insert() provides some efficient error
checking before the sforce request is made and, in some
cases, support for autotype_as_described.

If the method succeeds it returns the XMLRPC result
object. The actual response from sforce may be retrieved
by calling the result() method of that object. Refer to
the sforce API reference documentation for details on the
arguments and response members for each call. (When the
sforce documentation says 'struct', think 'hash'.)

If the method fails, it stores an error message in
$Sforce::Sfdc::errstr and returns false.

login
my $session_id = $sfdc->login(username => $email, password => $password);

Opens a connection to sforce, and stores the session
id and server url in the object for subsequent calls.

logout
$sfdc->logout();

Closes the connection to sforce. A new connection can
be opened with login() on the same object.

describe
Retrieves a list of valid entity types, or descriptive
information about an entity type.

If autotype_as_described is set, caches the descrip-
tion of an entity type for use in later calls. (See
"autotype_as_described".)

insert
Inserts a new entity into sforce.

If autotype_as_described is set, and describe has pre-
viously been called on the entity type, the field val-
ues in the record argument are automatically cast to
the appropriate types.

update
Updates an existing entity in sforce.

If autotype_as_described is set, and describe has pre-
viously been called on the entity type, the field val-
ues in the record argument are automatically cast to
the appropriate types.

delete
Deletes an entity in sforce.

query
Queries sforce for a list of entities that meet the
specified criteria.

For a filter query, if autotype_as_described is set,
and describe has previously been called on the entity
type, the field values in the filter argument are
automatically cast to the appropriate types.

batch
Performs a batch of insert, update, or delete opera-
tions.

If autotype_as_described is set, and describe has pre-
viously been called on the entity type, the field val-
ues in the arguments argument are automatically cast
to the appropriate types.

call
Calls the specified sfdc call.

Note that call() does not support auto-
type_as_described.

AUTHOR
Ronald J Kimball

Initial version based on XML::Sfdc by Ron Hess.

COPYRIGHT AND LICENSE
Copyright (C) 2003 Focalex, Inc.

Focalex, Inc., 90 Bridge St, Newton, MA 02458 USA

This library is free software; you can redistribute it
and/or modify it under the terms of the GNU Lesser General
Public License as published by the Free Software Founda-
tion; either version 2.1 of the License, or (at your
option) any later version.

This library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU Lesser General Public License for
more details.

You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to
the Free Software Foundation, Inc., 59 Temple Place, Suite
330, Boston, MA 02111-1307 USA

SEE ALSO
<http://www.sforce.com/>

XMLRPC::Lite, LWP::UserAgent
adamgadamg
Cool!
Ron HessRon Hess

Very cool, this is a big improvement, and well written doc too !

the naming looks fine, I will port some of my nightly jobs over to this module and let you know what i run into.

Thanks !.

anagramanagram
Hi Ronald-
Thanks a million! This is just what I've been looking for. Dropped it in and it worked without any trouble. I've now implemented a few things with it and am very pleased. A couple of comments fyi and a question:

1. In my application I save the session_id and server_url between instances. To tell the module to use the old ones (instead of logging in again), I do:

$sfdc->{'session_id'} = $sid;
$sfdc->{'server_url'} = $URL;

This works fine, of course, but isn't explicitly endorsed by the docs...

2. I removed the prepending of "Response error" to error strings so that I could just get back the raw sforce error message.

3. More general question: Is access of sforce through XMLRPC here to stay, or will things be migrating in the SOAP direction in the future?

Thanks again for posting this. It's been very helpful.

- Nicholas
rjkrjk
I'm very glad you're finding the module to be useful!

1. I had no idea that would work. I'm not sure the module should explicitly support it, but it won't explicitly prevent it either.

2. I can take out the prepending to error strings if that's not useful.

Also, I realized the error string doesn't include the fault code; I think I'll add a $err variable for that.

3. Uh oh, I don't know. I guess it wouldn't be too hard to convert this module to use SOAP instead of XML-RPC, if that happens.