The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

WWW::Salesforce - this class provides a simple abstraction layer between SOAP::Lite and <http://www.salesforce.com|Salesforce.com>.

DESCRIPTION

Because SOAP::Lite is somewhat of a pain, this module handles the tasks of dealing with it for you and provides a more intuitive interface a developer can interact with.

SYNOPSIS

 use WWW::Salesforce;
 my $sforce = WWW::Salesforce->new(
    #all parameters below are optional.  The values given are the defaults
    serverurl => 'https://www.salesforce.com/services/Soap/u/16.0',
    uri => 'urn:partner.soap.sforce.com',
    object_uri => 'urn:sobject.partner.soap.sforce.com',
    prefix => 'sforce'
 ); #This will confess its errors and die if it fails!
 
 $sforce->login('username', 'password') or die $sforce->errstr;

METHODS

new HASH
new

The new method creates the WWW::Salesforce object. No calls can be made with the object that's returned until you use the login method. If the creation of the object fails, WWW::Salesforce will confess its errors and die.

 my $sforce = WWW::Salesforce->new();

The following are the accepted input parameters:

serverurl

The default is 'https://www.salesforce.com/services/Soap/u/16.0'. You might want to use 'https://test.salesforce.com/services/Soap/u/16.0' to connect to your sandbox. Here is the documentation for login URLs: http://www.salesforce.com/us/developer/docs/api/Content/implementation_considerations.htm

uri

The default is 'urn:partner.soap.sforce.com'. Change this for the enterprise account, etc.

object_uri

The default is 'urn:sobject.partner.soap.sforce.com'. Change this for the enterprise account, etc.

prefix

The default is 'sforce'. You should probably leave this one be.

errstr

The errstr method returns the last error encountered with this object. Upon the failure of a method call, that method call will return 0 (false) and set the error string which you can obtain with this method.

 die "Uh oh, there was an error ". $sforce->errstr();
uid

The uid method returns the user ID string of the user you're currently logged in as. If you're not logged in, you will get an empty string.

 print "My user ID is: ", $sforce->uid(), "\n";

CORE METHODS

convertLead ARRAY

The convertLead method takes an array of WWW::Salesforce::LeadConvert objects. Use convertLead to convert a Lead into an Account and Contact, as well as (optionally) an Opportunity. To convert a Lead, your client application must be logged in with the "Convert Leads" permission and the "Edit" permission on leads, as well as "Create" and "Edit" on the Account, Contact, and Opportunity objects.

 use WWW::Salesforce::LeadConvert;

 ...

 my $lc = WWW::Salesforce::LeadConvert->new(
    leadId => '0FQ30000009gBn8',
    convertedStatus => 'Closed - Converted',
 );

 #I'm just providing a list of LeadConverts for example purposes.
 #you could just as easily only provide one LeadConvert
 my @lcrs = $sforce->convertLead( $lc, $lc, $lc, $lc ) or die $sforce->errstr();

 #loop through the LeadConvertResults
 for my $lcr ( @lcrs ) {
    print "convertLead for ", ($lcr->leadId()?$lcr->leadId():"invalid id"), " ";
    if ( $lcr->success() ) {
        print "passed!\n";
    }
    else {
        print "FAILED!\n";
        for my $err ( @{$lcr->errors()} ) {
            print $err->statusCode(), " ";
            print $err->message(), "\nOn Fields: ";
            print join ', ', @{$err->fields()};
        }
        print "\n";
    }
 }
login USERNAME, PASSWORD, TOKEN
login USERNAME, PASSWORD

The login method returns an object of type WWW::Salesforce::GetUserInfoResult if the login attempt was successful. Upon a successful login, the sessionId is saved so that developers need not worry about setting these values manually. Salesforce.com checks the IP address from which the client application is logging in, and blocks logins from unknown IP addresses. For a blocked login via the API, Salesforce.com returns a login fault. Then, the user must add their security token to the end of their password in order to log in. A security token is an automatically-generated key from Salesforce.com. For example, if a user's password is mypassword, and their security token is XXXXXXXXXX, then the user must enter mypasswordXXXXXXXXXX to log in. Users can obtain their security token by changing their password or resetting their security token via the Salesforce.com user interface. When a user changes their password or resets their security token, Salesforce.com sends a new security token to the email address on the user's Salesforce.com record. The security token is valid until a user resets their security token, changes their password, or has their password reset. When the security token is invalid, the user must repeat the login process to log in. To avoid this, the administrator can make sure the client's IP address is added to the organization's list of trusted IP addresses. For more information, see http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_concepts_security.htm#topic-title_login_token.

 $sforce->login( 'username', 'password', 'ypLbB47zm1qkM98Q3NWd4uWWqZ' )
    or die $sforce->errstr();

OR

 $sforce->login( 'username', 'password' ) or die $sforce->errstr();
 

OR

 my $info = $sforce->login( 'username', 'password' );
 die $sforce->errstr() unless $info;
 print $info->userId();
logout

The logout method logs the current user out and readies your object for another login.

 $sforce->logout() or die $sforce->errstr();

UTILITY METHODS

getServerTimestamp

Returns a string. Gets the current system timestamp (GMT) from the sforce Web service. The login method must be called prior to using this method.

 my $tstamp = $sforce->getServerTimestamp() or die $sforce->errstr;
 print $tstamp;
getUserInfo

Returns a WWW::Salesforce::GetuserInfoResult object. Use getUserInfo() to obtain personal information about the currently logged-in user. The login method must be called prior to using this method.

 my $userinfo = $sforce->getUserInfo() or die $sforce->errstr;
 print $userinfo->userId();
resetPassword USERID

Returns 1 or a string on success. Changes the desired user's password to a server-generated value. The login method must be called prior to using this method.

 #supply the user id of the person you want to reset
 my $passwd = $sforce->resetPassword( '00510000000tFa7AAE' );
 if ( $passwd ) {
         print "Yay!  Your new password is $password";
 }
 else {
         print "boo! ", $sforce->errstr;
 }
setPassword USERID, PASSWORD

Returns 1 or a string and sets the specified user's password to the specified value on success. The login method must be called prior to using this method.

 my $res = $sforce->setPassword( '00510000000tFa7AAE', 'foobar' );
 if ( $res ) {
         print "yay!";
 }
 else {
         print "boo! ", $sforce->errstr;
 }

SUPPORT

Please visit Salesforce.com's user/developer forums online for assistance with this module. You are free to contact the author directly if you are unable to resolve your issue online.

#perl on EFNet is also a place to get help. The author is 'genio' on that channel.

SEE ALSO

WWW::Salesforce::LeadConvert

WWW::Salesforce::GetUserInfo

DBD::Salesforce by Jun Shimizu

SOAP::Lite by Byrne Reese

Examples on Salesforce website:

http://www.salesforce.com/us/developer/docs/api/index.htm

AUTHORS

Chase Whitener <cwhitener at gmail dot com>

Thanks to:

Michael Blanco - Finding and fixing some bugs.

Garth Webb - Finding and fixing bugs. Adding some additional features and more constant types.

Ron Hess - Finding and fixing bugs. Adding some additional features. Adding more tests to the build. Providing a lot of other help.

Tony Stubblebine - Finding a bug and providing a fix.

Jun Shimizu - Providing more to the WWW::Salesforce::Constants module and submitting fixes for various other bugs.

Byrne Reese - <byrne at majordojo dot com> - Byrne Reese wrote the original Salesforce module.

COPYRIGHT

Copyright 2009, Chase Whitener.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.