WWW::SFDC - Wrappers around the Salesforce.com APIs.
version 0.33
WWW::SFDC provides a set of packages which you can use to build useful interactions with Salesforce.com's many APIs. Initially it was intended for the construction of powerful and flexible deployment tools.
use WWW::SFDC; my $session = WWW::SFDC->new( username => $username, password => $password, url => url, apiVersion => apiversion ); # This will do queryMore until it's got everything my @queryResult = $session->query('SELECT Id FROM Account');
Returns 1 if the org associated with the given credentials are a sandbox. Use to decide whether to sanitise metadata or similar.
This module is quite unstable, as it's early in its development cycle. I'm trying to avoid breaking too much, but until it hits 1.0, there is a risk of breakage.
Provides the lowest-level interaction with SOAP::Lite. Handles the SessionID and renews it when necessary.
Retrieves and caches the metadata objects as returned by DescribeMetadata for use when trying to interact with the filesystem etc.
Stores and manipulates lists of metadata for retrieving and deploying to and from Salesforce.com.
Wraps the Metadata API.
Wraps the Partner API.
Wraps the Tooling API.
Provides utilities for creating and extracting base-64 encoded zip files for Salesforce.com retrievals and deployments.
The following provides a starting point for a simple retrieval tool. Notice that after the initial setup of WWW::SFDC the login credentials are cached. In this example, you'd use _retrieveTimeMetadataChanges to remove files you didn't want to track, change sandbox outbound message endpoints to production, or similar.
Notice that I've tried to keep the manifest interface as fluent as possible - every method which doesn't have an obvious return value returns $self.
package ExampleRetrieval; use WWW::SFDC; use WWW::SFDC::Manifest; use WWW::SFDC::Zip qw'unzip'; my ($password, $username, $url, $apiVersion, $package); sub _retrieveTimeMetadataChanges { my ($path, $content) = @_; return $content; } my $client = WWW::SFDC->new( password => $password, username => $username, url => $url ); my $manifest = WWW::SFDC::Manifest->new( constants => $client->Constants, apiVersion => $apiVersion ) ->readFromFile($package) ->add( $session->Metadata->listMetadata( {type => 'Document', folder => 'Apps'}, {type => 'Document', folder => 'Developer_Documents'}, {type => 'EmailTemplate', folder => 'Asset'}, {type => 'ApexClass'} ) ); unzip 'src/', $session->Metadata->retrieveMetadata($manifest->manifest()), \&_retrieveTimeMetadataChanges;
Here's a similar example for deployments. You'll want to construct @filesToDeploy and $deployOptions context-sensitively!
package ExampleDeployment; use WWW::SFDC; use WWW::SFDC::Manifest; use WWW::SFDC::Zip qw'makezip'; my $client = WWW::SFDC->new( password => $password, username => $username, url => $url ); my $manifest = WWW::SFDC::Manifest ->new(constants => $client->Constants) ->addList(@filesToDeploy) ->writeToFile('src/package.xml'); my $zip = makezip 'src', $manifest->getFileList(), 'package.xml'; my $deployOptions = { singlePackage => 'true', rollbackOnError => 'true', checkOnly => 'true' }; $client->Metadata->deployMetadata($zip, $deployOptions);
To unsanitise some users' email address and change their profiles on a new sandbox, you might do something like this:
package ExampleUserSanitisation; use WWW::SFDC; use List::Util qw'first'; my $client = WWW::SFDC->new( username => $username, password => $password, url => $url ); my @users = ( {User => alexander.brett, Email => alex@example.com, Profile => $profileId}, {User => another.user, Email => a.n.other@example.com, Profile => $profileId}, ); $client->Partner->update( map { my $row = $_; my $original = first {$row->{Username} =~ /$$_{User}/} @users; +{ Id => $row->{Id}, ProfileId => $original->{Profile}, Email => $original->{Email}, } } $client->Partner->query( "SELECT Id, Username FROM User WHERE " . (join " OR ", map {"Username LIKE '%$_%'"} map {$_->{User}} @inputUsers) ) );
App::SFDC uses WWW::SFDC to provide a command-line application for interacting with Salesforce.com
Both of these modules offer more straightforward, comprehensive and mature wrappers around the Partner API than this module does at the moment. If all of your requirements can be fulfilled by that, you may be better off using them.
This module is designed for use in deployment applications, or when you want to juggle multiple APIs to provide complicated functionality.
Please report any bugs or feature requests at https://github.com/alexander-brett/WWW-SFDC/issues.
You can find documentation for this module with the perldoc command.
perldoc WWW::SFDC perldoc WWW::SFDC::Metadata ...
You can also look for information at https://github.com/alexander-brett/WWW-SFDC
Alexander Brett <alexander.brett@sophos.com>
This software is Copyright (c) 2015 by Sophos Limited.
This is free software, licensed under:
The MIT (X11) License
The full text of the license can be found in the LICENSE file included with this distribution.
To install WWW::SFDC, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::SFDC
CPAN shell
perl -MCPAN -e shell install WWW::SFDC
For more information on module installation, please visit the detailed CPAN module installation guide.