| 1 | package WWW::SFDC; | ||
| 2 | # ABSTRACT: Wrappers around the Salesforce.com APIs. | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use 5.12.0; | ||
| 7 | |||
| 8 | sub import { | ||
| 9 | my $class = shift; | ||
| 10 | |||
| 11 | @_ = qw(Apex Constants Manifest Metadata Partner SessionManager Tooling Zip) | ||
| 12 | unless @_; | ||
| 13 | |||
| 14 | for (@_) { | ||
| 15 | my $module = "WWW/SFDC/$_.pm"; | ||
| 16 | require $module; | ||
| 17 | } | ||
| 18 | |||
| 19 | } | ||
| 20 | |||
| 21 | 1; | ||
| 22 | |||
| 23 | __END__ | ||
| 24 | |||
| 25 | =pod | ||
| 26 | |||
| 27 | =head1 NAME | ||
| 28 | |||
| 29 | WWW::SFDC - Wrappers around the Salesforce.com APIs. | ||
| 30 | |||
| 31 | =head1 VERSION | ||
| 32 | |||
| 33 | version 0.22 | ||
| 34 | |||
| 35 | =head1 SYNOPSIS | ||
| 36 | |||
| 37 | WWW::SFDC provides a set of packages which you can use to build useful | ||
| 38 | interactions with Salesforce.com's many APIs. Initially it was intended | ||
| 39 | for the construction of powerful and flexible deployment tools. | ||
| 40 | |||
| 41 | use WWW::SFDC; # Import everything | ||
| 42 | |||
| 43 | use WWW::SFDC::Tooling; # Just the tooling API interface | ||
| 44 | |||
| 45 | use WWW::SFDC qw'Metadata Manifest'; | ||
| 46 | # Equivalent to importing WWW::SFDC::Metadata and WWW::SFDC::Manifest | ||
| 47 | |||
| 48 | =head1 CONTENTS | ||
| 49 | |||
| 50 | =over 4 | ||
| 51 | |||
| 52 | =item WWW::SFDC::SessionManager | ||
| 53 | |||
| 54 | Provides the lowest-level interaction with SOAP::Lite. Handles the | ||
| 55 | SessionID and renews it when necessary. | ||
| 56 | |||
| 57 | =item WWW::SFDC::Manifest | ||
| 58 | |||
| 59 | Stores and manipulates lists of metadata for retrieving and deploying | ||
| 60 | to and from Salesforce.com. | ||
| 61 | |||
| 62 | =item WWW::SFDC::Metadata | ||
| 63 | |||
| 64 | Wraps the Metadata API. | ||
| 65 | |||
| 66 | =item WWW::SFDC::Partner | ||
| 67 | |||
| 68 | Wraps the Partner API. | ||
| 69 | |||
| 70 | =item WWW::SFDC::Tooling | ||
| 71 | |||
| 72 | Wraps the Tooling API. | ||
| 73 | |||
| 74 | =item WWW::SFDC::Zip | ||
| 75 | |||
| 76 | Provides utilities for creating and extracting base-64 encoded zip | ||
| 77 | files for Salesforce.com retrievals and deployments. | ||
| 78 | |||
| 79 | =back | ||
| 80 | |||
| 81 | =head1 METADATA API EXAMPLES | ||
| 82 | |||
| 83 | The following provides a starting point for a simple retrieval tool. | ||
| 84 | Notice that after the initial setup of WWW::SFDC::Metadata the login | ||
| 85 | credentials are cached. In this example, you'd use | ||
| 86 | _retrieveTimeMetadataChanges to remove files you didn't want to track, | ||
| 87 | change sandbox outbound message endpoints to production, or similar. | ||
| 88 | |||
| 89 | Notice that I've tried to keep the interface as fluent as possible in | ||
| 90 | all of these modules - every method which doesn't have an obvious | ||
| 91 | return value returns $self. | ||
| 92 | |||
| 93 | package ExampleRetrieval; | ||
| 94 | |||
| 95 | use WWW::SFDC::Metadata; | ||
| 96 | use WWW::SFDC::Manifest; | ||
| 97 | use WWW::SFDC::Zip qw'unzip'; | ||
| 98 | |||
| 99 | WWW::SFDC::Metadata->instance(creds => { | ||
| 100 | password => $password, | ||
| 101 | username => $username, | ||
| 102 | url => $url | ||
| 103 | }); | ||
| 104 | |||
| 105 | my $manifest = WWW::SFDC::Manifest | ||
| 106 | ->readFromFile($manifestFile) | ||
| 107 | ->add( | ||
| 108 | WWW::SFDC::Metadata | ||
| 109 | ->instance() | ||
| 110 | ->listMetadata( | ||
| 111 | {type => 'Document', folder => 'Apps'}, | ||
| 112 | {type => 'Document', folder => 'Developer_Documents'}, | ||
| 113 | {type => 'EmailTemplate', folder => 'Asset'}, | ||
| 114 | {type => 'ApexClass'} | ||
| 115 | ) | ||
| 116 | ); | ||
| 117 | |||
| 118 | unzip | ||
| 119 | $destDir, | ||
| 120 | WWW::SFDC::Metadata->instance()->retrieveMetadata($manifest->manifest()), | ||
| 121 | \&_retrieveTimeMetadataChanges; | ||
| 122 | |||
| 123 | Here's a similar example for deployments. You'll want to construct | ||
| 124 | @filesToDeploy and $deployOptions context-sensitively! | ||
| 125 | |||
| 126 | package ExampleDeployment; | ||
| 127 | |||
| 128 | use WWW::SFDC::Metadata; | ||
| 129 | use WWW::SFDC::Manifest; | ||
| 130 | use WWW::SFDC::Zip qw'makezip'; | ||
| 131 | |||
| 132 | my $manifest = WWW::SFDC::Manifest | ||
| 133 | ->new() | ||
| 134 | ->addList(@filesToDeploy) | ||
| 135 | ->writeToFile($srcDir.'package.xml'); | ||
| 136 | |||
| 137 | my $zip = makezip | ||
| 138 | $srcDir, | ||
| 139 | $manifest->getFileList(), | ||
| 140 | 'package.xml'; | ||
| 141 | |||
| 142 | my $deployOptions = { | ||
| 143 | singlePackage => 'true', | ||
| 144 | rollbackOnError => 'true', | ||
| 145 | checkOnly => 'true' | ||
| 146 | }; | ||
| 147 | |||
| 148 | WWW::SFDC::Metadata->instance(creds => { | ||
| 149 | username=>$username, | ||
| 150 | password=>$password, | ||
| 151 | url=>$url | ||
| 152 | })->deployMetadata $zip, $deployOptions; | ||
| 153 | |||
| 154 | =head1 PARTNER API EXAMPLE | ||
| 155 | |||
| 156 | To unsanitise some users' email address and change their profiles | ||
| 157 | on a new sandbox, you might do something like this: | ||
| 158 | |||
| 159 | package ExampleUserSanitisation; | ||
| 160 | |||
| 161 | use WWW::SFDC::Partner; | ||
| 162 | use List::Util qw'first'; | ||
| 163 | |||
| 164 | WWW::SFDC::Partner->instance(creds => { | ||
| 165 | username => $username, | ||
| 166 | password => $password, | ||
| 167 | url => $url | ||
| 168 | }); | ||
| 169 | |||
| 170 | my @users = ( | ||
| 171 | {User => alexander.brett, Email => alex@example.com, Profile => $profileId}, | ||
| 172 | {User => another.user, Email => a.n.other@example.com, Profile => $profileId}, | ||
| 173 | ); | ||
| 174 | |||
| 175 | WWW::SFDC::Partner->instance()->update( | ||
| 176 | map { | ||
| 177 | my $row = $_; | ||
| 178 | my $original = first {$row->{Username} =~ /$$_{User}/} @users; | ||
| 179 | +{ | ||
| 180 | Id => $row->{Id}, | ||
| 181 | ProfileId => $original->{Profile}, | ||
| 182 | Email => $original->{Email}, | ||
| 183 | } | ||
| 184 | } WWW::SFDC::Partner->instance()->query( | ||
| 185 | "SELECT Id, Username FROM User WHERE " | ||
| 186 | . (join " OR ", map {"Username LIKE '%$_%'"} map {$_->{User}} @inputUsers) | ||
| 187 | ) | ||
| 188 | ); | ||
| 189 | |||
| 190 | =head1 BUGS | ||
| 191 | |||
| 192 | Please report any bugs or feature requests at L<https://github.com/alexander-brett/WWW-SFDC/issues>. | ||
| 193 | |||
| 194 | =head1 SUPPORT | ||
| 195 | |||
| 196 | You can find documentation for this module with the perldoc command. | ||
| 197 | |||
| 198 | perldoc WWW::SFDC | ||
| 199 | perldoc WWW::SFDC::Metadata | ||
| 200 | ... | ||
| 201 | |||
| 202 | You can also look for information at L<https://github.com/alexander-brett/WWW-SFDC> | ||
| 203 | |||
| 204 | =head1 AUTHOR | ||
| 205 | |||
| 206 | Alexander Brett <alexander.brett@sophos.com> | ||
| 207 | |||
| 208 | =head1 COPYRIGHT AND LICENSE | ||
| 209 | |||
| 210 | This software is Copyright (c) 2015 by Sophos Limited. | ||
| 211 | |||
| 212 | This is free software, licensed under: | ||
| 213 | |||
| 214 | The MIT (X11) License | ||
| 215 | |||
| 216 | The full text of the license can be found in the | ||
| 217 | F<LICENSE> file included with this distribution. | ||
| 218 | |||
| 219 | =cut |