Salesforce.pm

filter: Statementstmt 5.9% 33 / 557 Branchbran 0.0% 0 / 244 Conditioncond 0.0% 0 / 147 MC/DCmcdc 0.0% 0 / 90 Subroutinesub 14.0% 8 / 57 Podpod 90.4% 38 / 42 totaltotal 6.9% 79 / 1137 CC 185 SCAR 43.0
CC
185
Cov
3%
retrieve
210.0
login
132.0
update
132.0
CRAP 73.6
↑ Summary Salesforce/Deserializer.pm »
1 package WWW::Salesforce;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use SOAP::Lite (); # ( +trace => 'all', readable => 1, );#, outputxml => 1, );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use DateTime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use URI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 # use Data::Dumper;
10 4 ▶use WWW::Salesforce::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use WWW::Salesforce::Deserializer;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use WWW::Salesforce::Serializer;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 our $VERSION = '0.304';
15  
16 4 our $SF_PROXY = 'https://login.salesforce.com/services/Soap/u/52.0';
17 4 our $SF_URI = 'urn:partner.soap.sforce.com';
18 4 our $SF_PREFIX = 'sforce';
19 4 our $SF_SOBJECT_URI = 'urn:sobject.partner.soap.sforce.com';
20 4 our $SF_URIM = 'http://soap.sforce.com/2006/04/metadata';
21 4 our $SF_APIVERSION = '52.0';
22 # set webproxy if firewall blocks port 443 to SF_PROXY
23 4 our $WEB_PROXY = ''; # e.g., http://my.proxy.com:8080
24  
25  
26 =encoding utf8
27  
28 =head1 NAME
29  
30 WWW::Salesforce - This class provides a simple SOAP client for Salesforce.com.
31  
32 =head1 SYNOPSIS
33  
34 use Try::Tiny;
35 use WWW::Salesforce ();
36 try {
37 my $sforce = WWW::Salesforce->login(
38 username => 'foo',
39 password => 'password' . 'pass_token',
40 serverurl => 'https://test.salesforce.com',
41 version => '52.0' # must be a string
42 );
43 my $res = $sforce->query(query => 'select Id, Name from Account');
44 say "Found this many: ", $res->valueof('//queryResponse/result/size');
45 my @records = $res->valueof('//queryResponse/result/records');
46 say $records[0];
47 }
48 catch {
49 # log or whatever. we'll just die for example
50 die "Could not perform an action: $_";
51 }
52  
53 =head1 DESCRIPTION
54  
55 This class provides a simple abstraction layer between L<SOAP::Lite> and
56 L<Salesforce|https://www.salesforce.com>. Because L<SOAP::Lite> does not
57 support C<complexTypes>, and document/literal encoding is limited, this module
58 works around those limitations and provides a more intuitive interface a
59 developer can interact with.
60  
61 =head1 CONSTRUCTOR ARGUMENTS
62  
63 Given that L<WWW::Salesforce> doesn't have attributes in the traditional
64 sense, the following arguments, rather than attributes, can be passed
65 into the constructor.
66  
67 =head2 password
68  
69 my $sforce = WWW::Salesforce->new(password => 'foobar1232131');
70  
71 The password is a combination of your Salesforce password and your user's
72 L<Security Token|https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_concepts_security.htm>.
73  
74 =head2 serverurl
75  
76 my $sforce = WWW::Salesforce->new(serverurl => 'https://login.salesforce.com');
77 # or maybe one of your developer instances
78 $sforce = WWW::Salesforce->new(serverurl => 'https://test.salesforce.com');
79  
80 When you login to Salesforce, it's sometimes useful to login to one of your sandbox or
81 other instances. All you need is the base URL here.
82  
83 =head2 username
84  
85 my $sforce = WWW::Salesforce->new(username => 'foo@bar.com');
86  
87 When you login to Salesforce, your username is necessary.
88  
89 =head2 version
90  
91 my $sforce = WWW::Salesforce->new(version => '52.0');
92  
93 Salesforce makes changes to their API and luckily for us, they version those changes.
94 You can choose which API version you want to use by passing this argument. However, it
95 B<must> be a string.
96  
97 =head1 CONSTRUCTORS
98  
99 L<WWW::Salesforce> constructs its instance and immediately logs you into the
100 L<Salesforce|https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_login.htm>
101 API. So that there's less confusion, we have the traditional constructor as well as a
102 second constructor named login.
103  
104 =head2 new
105  
106 my $sforce = WWW::Salesforce->new(
107 username => 'foo@bar.com',
108 password => 'password' . 'security_token',
109 serverurl => 'https://login.salesforce.com',
110 version => '52.0'
111 );
112  
113 When you create a new instance, the L<WWW::Salesforce/username> and L<WWW::Salesforce/password>
114 arguments are required. The others are not required. After construction, these items are
115 not mutable.
116  
117 =cut
118  
119 0 ▶sub new { return shift->login(@_); }
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
120  
121  
122 =head2 login
123  
124 my $sforce = WWW::Salesforce->login(
125 username => 'foo@bar.com',
126 password => 'password' . 'security_token',
127 serverurl => 'https://login.salesforce.com',
128 version => '52.0'
129 );
130  
131 When you create a new instance, the L<WWW::Salesforce/username> and L<WWW::Salesforce/password>
132 arguments are required. The others are not required. After construction, these items are
133 not mutable.
134  
135 =cut
136  
137 sub login {
138 0 ▶ my $class = shift;
Subroutine login: not called CC=11 SCAR=48.8
Pod documented
139 0 my (%params) = @_;
140  
141 0 ▶ unless (defined $params{'username'} and length $params{'username'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $params{"username"} and length $params{"username"}) 0 0 0
Condition0%0/3
defined $params{"username"} and length $params{"username"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $params{"username"} and length $params{"username"}
defined $params{"username"} length $params{"username"}
Truth table0%0/3
A and B
A= defined $params{"username"}B= length $params{"username"}
ABresult
0X0
100
111
142 0 die("WWW::Salesforce::login() requires a username");
143 }
144 0 ▶ unless (defined $params{'password'} and length $params{'password'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $params{"password"} and length $params{"password"}) 0 0 0
Condition0%0/3
defined $params{"password"} and length $params{"password"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $params{"password"} and length $params{"password"}
defined $params{"password"} length $params{"password"}
Truth table0%0/3
A and B
A= defined $params{"password"}B= length $params{"password"}
ABresult
0X0
100
111
145 0 die("WWW::Salesforce::login() requires a password");
146 }
147  
148 # build the login URL
149 0 ▶ my $version = $params{version} || $SF_APIVERSION || '52.0';
Condition0%0/5
$params{'version'} || $WWW::Salesforce::SF_APIVERSION || '52.0'
l!l
00
$params{"version"} or $WWW::Salesforce::SF_APIVERSION
l!l&&r!l&&!r
000
MC/DC0%0/2
$params{'version'} || $WWW::Salesforce::SF_APIVERSION || '52.0'
$params{"version"} $WWW::Salesforce::SF_APIVERSION
Truth table0%0/3
A or B
A= $params{"version"}B= $WWW::Salesforce::SF_APIVERSION
ABresult
1X1
011
000
150 my $url
151 = URI->new($params{serverurl}
152 0 ▶ || $SF_PROXY
Condition0%0/5
$params{'serverurl'} || $WWW::Salesforce::SF_PROXY || 'https://login.salesforce.com'
l!l
00
$params{"serverurl"} or $WWW::Salesforce::SF_PROXY
l!l&&r!l&&!r
000
MC/DC0%0/2
$params{'serverurl'} || $WWW::Salesforce::SF_PROXY || 'https://login.salesforce.com'
$params{"serverurl"} $WWW::Salesforce::SF_PROXY
Truth table0%0/3
A or B
A= $params{"serverurl"}B= $WWW::Salesforce::SF_PROXY
ABresult
1X1
011
000
153 || 'https://login.salesforce.com');
154 0 $url->path('/services/Soap/u/' . $version);
155  
156 my $self = {
157 sf_user => $params{'username'},
158 0 sf_pass => $params{'password'},
159 sf_serverurl => $url->as_string(),
160 sf_version => $version,
161 sf_sid => undef,
162 };
163 0 bless $self, $class;
164  
165 0 my $client = $self->_get_client();
166 my $r = $client->login(
167 SOAP::Data->name('username' => $self->{'sf_user'}),
168 0 SOAP::Data->name('password' => $self->{'sf_pass'})
169 );
170 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
171 die sprintf("could not login, user %s, pass %s",
172 0 $self->{'sf_user'}, $self->{'sf_pass'});
173 }
174 0 ▶ if ($r->fault()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
175 0 die($r->faultstring());
176 }
177  
178 0 $self->{'sf_sid'} = $r->valueof('//loginResponse/result/sessionId');
179 0 $self->{'sf_uid'} = $r->valueof('//loginResponse/result/userId');
180 0 $self->{'sf_serverurl'} = $r->valueof('//loginResponse/result/serverUrl');
181 0 $self->{'sf_metadataServerUrl'}
182 = $r->valueof('//loginResponse/result/metadataServerUrl');
183 0 return $self;
184 }
185  
186 =head1 METHODS
187  
188 =head2 convertLead( HASH )
189  
190 The C<convertLead> method returns an object of type SOAP::SOM if the login attempt was successful, and 0 otherwise.
191  
192 Converts a Lead into an Account, Contact, or (optionally) an Opportunity
193  
194 The following are the accepted input parameters:
195  
196 =over
197  
198 =item %hash_of_array_references
199  
200 leadId => [ 2345, 5678, ],
201 contactId => [ 9876, ],
202  
203 =back
204  
205 =cut
206  
207 sub convertLead {
208 0 ▶ my $self = shift;
Subroutine convertLead: not called CC=9 SCAR=45.0
Pod documented
209 0 my (%in) = @_;
210  
211 0 ▶ if ( !keys %in ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %in) 0 0 0
212 0 die("Expected a hash of arrays.");
213 }
214  
215 #take in data to be passed in our call
216 0 my @data;
217 0 for my $key ( keys %in ) {
218 0 ▶ if ( ref( $in{$key} ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $in{$key} eq 'ARRAY') { } 0 0 0
219 0 for my $elem ( @{ $in{$key} } ) {
220 0 my $dat = SOAP::Data->name( $key => $elem );
221 0 push @data, $dat;
222 }
223 }
224 else {
225 0 my $dat = SOAP::Data->name( $key => $in{$key} );
226 0 push @data, $dat;
227 }
228 }
229 0 ▶ if ( scalar @data < 1 || scalar @data > 200 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @data < 1 or scalar @data > 200) 0 0 0
Condition0%0/3
scalar @data < 1 or scalar @data > 200
l!l&&r!l&&!r
000
MC/DC0%0/2
scalar @data < 1 or scalar @data > 200
scalar @data < 1 scalar @data > 200
Truth table0%0/3
A or B
A= scalar @data < 1B= scalar @data > 200
ABresult
1X1
011
000
230 0 die("convertLead converts up to 200 objects, no more.");
231 }
232  
233 #got the data lined up, make the call
234 0 my $client = $self->_get_client(1);
235 0 my $r = $client->convertLead(
236 SOAP::Data->name( "leadConverts" => \SOAP::Data->value(@data) ),
237 $self->_get_session_header() );
238  
239 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
240 0 die "cound not convertLead";
241 }
242 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
243 0 die( $r->faultstring() );
244 }
245 0 return $r;
246 }
247  
248 =head2 create( HASH )
249  
250 Adds one new individual objects to your organization's data. This takes as input a HASH containing the fields (the keys of the hash) and the values of the record you wish to add to your organization.
251 The hash must contain the 'type' key in order to identify the type of the record to add.
252  
253 Returns a SOAP::Lite object. Success of this operation can be gleaned from
254 the envelope result.
255  
256 $r->envelope->{Body}->{createResponse}->{result}->{success};
257  
258 =cut
259  
260 sub create {
261 0 ▶ my $self = shift;
Subroutine create: not called CC=5 SCAR=34.0
Pod documented
262 0 my (%in) = @_;
263  
264 0 ▶ if ( !keys %in ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %in) 0 0 0
265 0 die("Expected a hash of arrays.");
266 }
267 0 my $client = $self->_get_client(1);
268 0 my $method =
269 SOAP::Data->name("create")->prefix($SF_PREFIX)->uri($SF_URI)
270 ->attr( { 'xmlns:sfons' => $SF_SOBJECT_URI } );
271  
272 0 my $type = $in{'type'};
273 0 delete( $in{'type'} );
274  
275 0 my @elems;
276 0 foreach my $key ( keys %in ) {
277 push @elems,
278 0 SOAP::Data->prefix('sfons')->name( $key => $in{$key} )
279 ->type( WWW::Salesforce::Constants->type( $type, $key ) );
280 }
281  
282 0 my $r = $client->call(
283 $method => SOAP::Data->name( 'sObjects' => \SOAP::Data->value(@elems) )
284 ->attr( { 'xsi:type' => 'sfons:' . $type } ),
285 $self->_get_session_header()
286 );
287 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
288 0 die "could not call method $method";
289 }
290 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
291 0 die( $r->faultstring() );
292 }
293 0 return $r;
294 }
295  
296  
297 =head2 delete( ARRAY )
298  
299 Deletes one or more individual objects from your organization's data.
300 This subroutine takes as input an array of SCALAR values, where each SCALAR is an C<sObjectId>.
301  
302 =cut
303  
304 sub delete {
305 0 ▶ my $self = shift;
Subroutine delete: not called CC=6 SCAR=37.4
Pod documented
306  
307 0 my $client = $self->_get_client(1);
308 0 my $method = SOAP::Data->name("delete")->prefix($SF_PREFIX)->uri($SF_URI);
309  
310 0 my @elems;
311 0 foreach my $id (@_) {
312 0 push @elems, SOAP::Data->name( 'ids' => $id )->type('tns:ID');
313 }
314  
315 0 ▶ if ( scalar @elems < 1 || scalar @elems > 200 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @elems < 1 or scalar @elems > 200) 0 0 0
Condition0%0/3
scalar @elems < 1 or scalar @elems > 200
l!l&&r!l&&!r
000
MC/DC0%0/2
scalar @elems < 1 or scalar @elems > 200
scalar @elems < 1 scalar @elems > 200
Truth table0%0/3
A or B
A= scalar @elems < 1B= scalar @elems > 200
ABresult
1X1
011
000
316 0 die("delete takes anywhere from 1 to 200 ids to delete.");
317 }
318  
319 0 my $r = $client->call(
320 $method => @elems,
321 $self->_get_session_header()
322 );
323 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
324 0 die "could not call method $method";
325 }
326 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
327 0 die( $r->faultstring() );
328 }
329 0 return $r;
330 }
331  
332  
333 =head2 describeGlobal()
334  
335 Retrieves a list of available objects for your organization's data.
336 You can then iterate through this list and use C<describeSObject()> to obtain metadata about individual objects.
337 This method calls the Salesforce L<describeGlobal method|https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_describeglobal.htm>.
338  
339 =cut
340  
341 sub describeGlobal {
342 0 ▶ my $self = shift;
Subroutine describeGlobal: not called CC=3 SCAR=24.8
Pod documented
343  
344 0 my $client = $self->_get_client(1);
345 0 my $method =
346 SOAP::Data->name("describeGlobal")->prefix($SF_PREFIX)->uri($SF_URI);
347  
348 0 my $r = $client->call( $method, $self->_get_session_header() );
349 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
350 0 die "could not call method $method";
351 }
352 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
353 0 die( $r->faultstring() );
354 }
355 0 return $r;
356 }
357  
358 =head2 describeLayout( HASH )
359  
360 Describes metadata about a given page layout, including layouts for edit and display-only views and record type mappings.
361  
362 =over
363  
364 =item type
365  
366 The type of the object you wish to have described.
367  
368 =back
369  
370 =cut
371  
372 sub describeLayout {
373 0 ▶ my $self = shift;
Subroutine describeLayout: not called CC=5 SCAR=34.0
Pod documented
374 0 my (%in) = @_;
375  
376 0 ▶ if ( !defined $in{'type'} or !length $in{'type'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"type"} and length $in{"type"}) 0 0 0
Condition0%0/3
defined $in{"type"} and length $in{"type"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"type"} and length $in{"type"}
defined $in{"type"} length $in{"type"}
Truth table0%0/3
A and B
A= defined $in{"type"}B= length $in{"type"}
ABresult
0X0
100
111
377 0 die("Expected hash with key 'type'");
378 }
379 0 my $client = $self->_get_client(1);
380 0 my $method =
381 SOAP::Data->name("describeLayout")->prefix($SF_PREFIX)->uri($SF_URI);
382 my $r = $client->call(
383 $method =>
384 0 SOAP::Data->prefix($SF_PREFIX)->name( 'sObjectType' => $in{'type'} )
385 ->type('xsd:string'),
386 $self->_get_session_header()
387 );
388 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
389 0 die "could not call method $method";
390 }
391 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
392 0 die( $r->faultstring() );
393 }
394 0 return $r;
395 }
396  
397  
398 =head2 describeSObject( HASH )
399  
400 Describes metadata (field list and object properties) for the specified object.
401  
402 =over
403  
404 =item type
405  
406 The type of the object you wish to have described.
407  
408 =back
409  
410 =cut
411  
412 sub describeSObject {
413 0 ▶ my $self = shift;
Subroutine describeSObject: not called CC=5 SCAR=34.0
Pod documented
414 0 my (%in) = @_;
415  
416 0 ▶ if ( !defined $in{'type'} or !length $in{'type'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"type"} and length $in{"type"}) 0 0 0
Condition0%0/3
defined $in{"type"} and length $in{"type"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"type"} and length $in{"type"}
defined $in{"type"} length $in{"type"}
Truth table0%0/3
A and B
A= defined $in{"type"}B= length $in{"type"}
ABresult
0X0
100
111
417 0 die("Expected hash with key 'type'");
418 }
419  
420 0 my $client = $self->_get_client(1);
421 0 my $method =
422 SOAP::Data->name("describeSObject")->prefix($SF_PREFIX)->uri($SF_URI);
423  
424 my $r = $client->call(
425 $method =>
426 0 SOAP::Data->prefix($SF_PREFIX)->name( 'sObjectType' => $in{'type'} )
427 ->type('xsd:string'),
428 $self->_get_session_header()
429 );
430 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
431 0 die "could not call method $method";
432 }
433 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
434 0 die( $r->faultstring() );
435 }
436 0 return $r;
437 }
438  
439 =head2 describeSObjects( type => ['Account','Contact','CustomObject__c'] )
440  
441 An array based version of describeSObject; describes metadata (field list and object properties) for the specified object or array of objects.
442  
443 =cut
444  
445 sub describeSObjects {
446 0 ▶ my $self = shift;
Subroutine describeSObjects: not called CC=6 SCAR=37.4
Pod documented
447 0 my %in = @_;
448  
449 0 ▶ if ( !defined $in{type}
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $in{"type"} or ref $in{"type"} ne "ARRAY" or not scalar @{$in{"type"};}) 0 0 0
Condition0%0/6
not defined $in{"type"} or ref $in{"type"} ne "ARRAY" or not scalar @{$in{"type"};}
l!l&&r!l&&!r
000
not defined $in{"type"} or ref $in{"type"} ne "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $in{"type"} or ref $in{"type"} ne "ARRAY" or not scalar @{$in{"type"};}
not defined $in{"type"} ref $in{"type"} ne "ARRAY" not scalar @{$in{"type"};}
Truth table0%0/4
not(A) or B or not(C)
A= not defined $in{"type"}B= ref $in{"type"} ne "ARRAY"C= not scalar @{$in{"type"};}
ABCresult
1XX1
01X1
0011
0000
450 or ref $in{type} ne 'ARRAY'
451 0 or !scalar @{ $in{type} } )
452 {
453 0 die "Expected hash with key 'type' containing array reference";
454 }
455  
456 0 my $client = $self->_get_client(1);
457 0 my $method =
458 SOAP::Data->name("describeSObjects")->prefix($SF_PREFIX)->uri($SF_URI);
459  
460 my $r = $client->call(
461 $method => SOAP::Data->prefix($SF_PREFIX)->name('sObjectType')
462 0 ->value( @{ $in{'type'} } )->type('xsd:string'),
463 $self->_get_session_header()
464 );
465  
466 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
467 0 die "could not execute method $method";
468 }
469 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
470 0 die( $r->faultstring() );
471 }
472 0 return $r;
473 }
474  
475 =head2 describeTabs()
476  
477 Use the C<describeTabs> call to obtain information about the standard and custom apps to which the logged-in user has access. The C<describeTabs> call returns the minimum required metadata that can be used to render apps in another user interface. Typically this call is used by partner applications to render Salesforce data in another user interface.
478  
479 =cut
480  
481 sub describeTabs {
482 0 ▶ my $self = shift;
Subroutine describeTabs: not called CC=3 SCAR=24.8
Pod documented
483 0 my $client = $self->_get_client(1);
484 0 my $method =
485 SOAP::Data->name("describeTabs")->prefix($SF_PREFIX)->uri($SF_URI);
486  
487 0 my $r = $client->call( $method, $self->_get_session_header() );
488 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
489 0 die "could not call method $method";
490 }
491 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
492 0 die( $r->faultstring() );
493 }
494 0 return $r;
495 }
496  
497 # TODO: remove in version 0.400
498 sub get_client {
499 0 ▶ warn "The method: get_client() has always been private. It is now deprecated and will be removed in version 0.400.";
Subroutine get_client: not called CC=1 SCAR=6.9
Pod undocumented
500 0 return shift->_get_client(@_);
501 }
502  
503 # TODO: remove in version 0.400
504 sub get_session_header {
505 0 ▶ warn "The method: get_session_header() has always been private. It is now deprecated and will be removed in version 0.400.";
Subroutine get_session_header: not called CC=1 SCAR=6.9
Pod undocumented
506 0 return shift->_get_session_header(@_);
507 }
508  
509  
510 =head2 get_session_id()
511  
512 Gets the Salesforce SID
513  
514 =cut
515  
516 sub get_session_id {
517 0 ▶ my ($self) = @_;
Subroutine get_session_id: not called CC=1 SCAR=6.9
Pod documented
518  
519 0 return $self->{sf_sid};
520 }
521  
522  
523 =head2 get_user_id()
524  
525 Gets the Salesforce UID
526  
527 =cut
528  
529 sub get_user_id {
530 0 ▶ my ($self) = @_;
Subroutine get_user_id: not called CC=1 SCAR=6.9
Pod documented
531  
532 0 return $self->{sf_uid};
533 }
534  
535  
536 =head2 get_username()
537  
538 Gets the Salesforce Username
539  
540 =cut
541  
542 sub get_username {
543 0 ▶ my ($self) = @_;
Subroutine get_username: not called CC=1 SCAR=6.9
Pod documented
544  
545 0 return $self->{sf_user};
546 }
547  
548  
549 =head2 getDeleted( HASH )
550  
551 Retrieves the list of individual objects that have been deleted within the given time span for the specified object.
552  
553 =over
554  
555 =item type
556  
557 Identifies the type of the object you wish to find deletions for.
558  
559 =item start
560  
561 A string identifying the start date/time for the query
562  
563 =item end
564  
565 A string identifying the end date/time for the query
566  
567 =back
568  
569 =cut
570  
571 sub getDeleted {
572 0 ▶ my $self = shift;
Subroutine getDeleted: not called CC=9 SCAR=45.0
Pod documented
573 0 my (%in) = @_;
574  
575 0 ▶ if ( !defined $in{'type'} || !length $in{'type'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"type"} and length $in{"type"}) 0 0 0
Condition0%0/3
defined $in{"type"} and length $in{"type"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"type"} and length $in{"type"}
defined $in{"type"} length $in{"type"}
Truth table0%0/3
A and B
A= defined $in{"type"}B= length $in{"type"}
ABresult
0X0
100
111
576 0 die("Expected hash with key of 'type'");
577 }
578 0 ▶ if ( !defined $in{'start'} || !length $in{'start'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"start"} and length $in{"start"}) 0 0 0
Condition0%0/3
defined $in{"start"} and length $in{"start"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"start"} and length $in{"start"}
defined $in{"start"} length $in{"start"}
Truth table0%0/3
A and B
A= defined $in{"start"}B= length $in{"start"}
ABresult
0X0
100
111
579 0 die("Expected hash with key of 'start' which is a date");
580 }
581 0 ▶ if ( !defined $in{'end'} || !length $in{'end'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"end"} and length $in{"end"}) 0 0 0
Condition0%0/3
defined $in{"end"} and length $in{"end"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"end"} and length $in{"end"}
defined $in{"end"} length $in{"end"}
Truth table0%0/3
A and B
A= defined $in{"end"}B= length $in{"end"}
ABresult
0X0
100
111
582 0 die("Expected hash with key of 'end' which is a date");
583 }
584  
585 0 my $client = $self->_get_client(1);
586 0 my $method =
587 SOAP::Data->name("getDeleted")->prefix($SF_PREFIX)->uri($SF_URI);
588 my $r = $client->call(
589 $method =>
590 SOAP::Data->prefix($SF_PREFIX)->name( 'sObjectType' => $in{'type'} )
591 ->type('xsd:string'),
592 SOAP::Data->prefix($SF_PREFIX)->name( 'startDate' => $in{'start'} )
593 ->type('xsd:dateTime'),
594 SOAP::Data->prefix($SF_PREFIX)
595 0 ->name( 'endDate' => $in{'end'} )
596 ->type('xsd:dateTime'),
597 $self->_get_session_header()
598 );
599 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
600 0 die "could not call method $method";
601 }
602 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
603 0 die( $r->faultstring() );
604 }
605 0 return $r;
606 }
607  
608  
609 =head2 getServerTimestamp()
610  
611 Retrieves the current system timestamp (GMT) from the Salesforce web service.
612  
613 =cut
614  
615 sub getServerTimestamp {
616 0 ▶ my $self = shift;
Subroutine getServerTimestamp: not called CC=3 SCAR=24.8
Pod documented
617 0 my $client = $self->_get_client(1);
618 0 my $r = $client->getServerTimestamp( $self->_get_session_header() );
619 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
620 0 die "could not getServerTimestamp";
621 }
622 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
623 0 die( $r->faultstring() );
624 }
625 0 return $r;
626 }
627  
628 =head2 getUpdated( HASH )
629  
630 Retrieves the list of individual objects that have been updated (added or changed) within the given time span for the specified object.
631  
632 =over
633  
634 =item type
635  
636 Identifies the type of the object you wish to find updates for.
637  
638 =item start
639  
640 A string identifying the start date/time for the query
641  
642 =item end
643  
644 A string identifying the end date/time for the query
645  
646 =back
647  
648 =cut
649  
650 sub getUpdated {
651 0 ▶ my $self = shift;
Subroutine getUpdated: not called CC=9 SCAR=45.0
Pod documented
652 0 my (%in) = @_;
653  
654 0 ▶ if ( !defined $in{'type'} || !length $in{'type'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"type"} and length $in{"type"}) 0 0 0
Condition0%0/3
defined $in{"type"} and length $in{"type"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"type"} and length $in{"type"}
defined $in{"type"} length $in{"type"}
Truth table0%0/3
A and B
A= defined $in{"type"}B= length $in{"type"}
ABresult
0X0
100
111
655 0 die("Expected hash with key of 'type'");
656 }
657 0 ▶ if ( !defined $in{'start'} || !length $in{'start'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"start"} and length $in{"start"}) 0 0 0
Condition0%0/3
defined $in{"start"} and length $in{"start"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"start"} and length $in{"start"}
defined $in{"start"} length $in{"start"}
Truth table0%0/3
A and B
A= defined $in{"start"}B= length $in{"start"}
ABresult
0X0
100
111
658 0 die("Expected hash with key of 'start' which is a date");
659 }
660 0 ▶ if ( !defined $in{'end'} || !length $in{'end'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"end"} and length $in{"end"}) 0 0 0
Condition0%0/3
defined $in{"end"} and length $in{"end"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"end"} and length $in{"end"}
defined $in{"end"} length $in{"end"}
Truth table0%0/3
A and B
A= defined $in{"end"}B= length $in{"end"}
ABresult
0X0
100
111
661 0 die("Expected hash with key of 'end' which is a date");
662 }
663  
664 0 my $client = $self->_get_client(1);
665 0 my $method =
666 SOAP::Data->name("getUpdated")->prefix($SF_PREFIX)->uri($SF_URI);
667 my $r = $client->call(
668 $method =>
669 SOAP::Data->prefix($SF_PREFIX)->name( 'sObjectType' => $in{'type'} )
670 ->type('xsd:string'),
671 SOAP::Data->prefix($SF_PREFIX)->name( 'startDate' => $in{'start'} )
672 ->type('xsd:dateTime'),
673 SOAP::Data->prefix($SF_PREFIX)
674 0 ->name( 'endDate' => $in{'end'} )
675 ->type('xsd:dateTime'),
676 $self->_get_session_header()
677 );
678 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
679 0 die "could not call method $method";
680 }
681 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
682 0 die( $r->faultstring() );
683 }
684 0 return $r;
685 }
686  
687  
688 =head2 getUserInfo( HASH )
689  
690 Retrieves personal information for the user associated with the current session.
691  
692 =over
693  
694 =item user
695  
696 A user ID
697  
698 =back
699  
700 =cut
701  
702 sub getUserInfo {
703 0 ▶ my $self = shift;
Subroutine getUserInfo: not called CC=3 SCAR=24.8
Pod documented
704 0 my $client = $self->_get_client(1);
705 0 my $r = $client->getUserInfo( $self->_get_session_header() );
706 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
707 0 die "could not getUserInfo";
708 }
709 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
710 0 die( $r->faultstring() );
711 }
712 0 return $r;
713 }
714  
715 =head2 logout()
716  
717 Ends the session for the logged-in user issuing the call. No arguments are needed.
718 Useful to avoid hitting the limit of ten open sessions per login.
719 L<Logout API Call|http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_logout.htm>
720  
721 =cut
722  
723 sub logout {
724 0 ▶ my $self = shift;
Subroutine logout: not called CC=3 SCAR=24.8
Pod documented
725  
726 0 my $client = $self->_get_client(1);
727 0 my $method =
728 SOAP::Data->name("logout")->prefix($SF_PREFIX)->uri($SF_URI);
729 0 my $r = $client->call( $method, $self->_get_session_header() );
730 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
731 0 die "could not call method $method";
732 }
733 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
734 0 die( $r->faultstring() );
735 }
736 0 return $r;
737 }
738  
739 =head2 query
740  
741 my $res = $sf->query(query => 'SELECT Id, Name FROM Account');
742 $res = $sf->query(query => 'SELECT Id, Name FROM Account', limit => 20);
743 # records as an array
744 my @records = $res->valueof('//QueryResult/result/records');
745 # number of records returned (int)
746 my $number = $res->valueof('//QueryResult/result/size');
747 # When our query has more results than our limit, we get paged results
748 my $done = $res->valueof('//queryResponse/result/done');
749 while (!$done) {
750 my $locator = $res->valueof('//queryResponse/result/queryLocator');
751 # use that locator for the queryMore method
752 }
753  
754 Executes a L<query|https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_query.htm>
755 against the specified object and returns data that matches the specified
756 criteria.
757  
758 The method takes in a hash with two potential keys, C<query> and C<limit>.
759  
760 The C<query> key is required and should contain an
761 L<SOQL|https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql.htm>
762 query string.
763  
764 The C<limit> key sets the batch size, or size of the result returned.
765 This is helpful in producing paginated results, or fetching small sets
766 of data at a time.
767  
768 =cut
769  
770 sub query {
771 0 ▶ my $self = shift;
Subroutine query: not called CC=9 SCAR=45.0
Pod documented
772 0 my (%in) = @_;
773 0 ▶ if (!defined $in{'query'} || !length $in{'query'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"query"} and length $in{"query"}) 0 0 0
Condition0%0/3
defined $in{"query"} and length $in{"query"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"query"} and length $in{"query"}
defined $in{"query"} length $in{"query"}
Truth table0%0/3
A and B
A= defined $in{"query"}B= length $in{"query"}
ABresult
0X0
100
111
774 0 die("A query is needed for the query() method.");
775 }
776 0 ▶ if (!defined $in{'limit'} || $in{'limit'} !~ m/^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"limit"} and $in{"limit"} =~ /^\d+$/) 0 0 0
Condition0%0/3
defined $in{"limit"} and $in{"limit"} =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"limit"} and $in{"limit"} =~ /^\d+$/
defined $in{"limit"} $in{"limit"} =~ /^\d+$/
Truth table0%0/3
A and B
A= defined $in{"limit"}B= $in{"limit"} =~ /^\d+$/
ABresult
0X0
100
111
777 0 $in{'limit'} = 500;
778 }
779 0 ▶ if ($in{'limit'} < 1 || $in{'limit'} > 2000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in{"limit"} < 1 or $in{"limit"} > 2000) 0 0 0
Condition0%0/3
$in{"limit"} < 1 or $in{"limit"} > 2000
l!l&&r!l&&!r
000
MC/DC0%0/2
$in{"limit"} < 1 or $in{"limit"} > 2000
$in{"limit"} < 1 $in{"limit"} > 2000
Truth table0%0/3
A or B
A= $in{"limit"} < 1B= $in{"limit"} > 2000
ABresult
1X1
011
000
780 0 die("A query's limit cannot exceed 2000. 500 is default.");
781 }
782  
783 my $limit
784 = SOAP::Header->name(
785 0 'QueryOptions' => \SOAP::Header->name('batchSize' => $in{'limit'}))
786 ->prefix($SF_PREFIX)->uri($SF_URI);
787 0 my $client = $self->_get_client();
788 0 my $r = $client->query(SOAP::Data->type('string' => $in{'query'}),
789 $limit, $self->_get_session_header());
790  
791 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
792 0 die "could not query " . $in{'query'};
793 }
794 0 ▶ if ($r->fault()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
795 0 die($r->faultstring());
796 }
797 0 return $r;
798 }
799  
800 =head2 queryAll( HASH )
801  
802 Executes a query against the specified object and returns data that matches the
803 specified criteria including archived and deleted objects.
804  
805 =over
806  
807 =item query
808  
809 The query string to use for the query. The query string takes the form of a I<basic> SQL statement. For example, "SELECT Id,Name FROM Account".
810  
811 =item limit
812  
813 This sets the batch size, or size of the result returned. This is helpful in producing paginated results, or fetch small sets of data at a time.
814  
815 =back
816  
817 =cut
818  
819 sub queryAll {
820 0 ▶ my $self = shift;
Subroutine queryAll: not called CC=9 SCAR=45.0
Pod documented
821 0 my (%in) = @_;
822 0 ▶ if ( !defined $in{'query'} || !length $in{'query'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"query"} and length $in{"query"}) 0 0 0
Condition0%0/3
defined $in{"query"} and length $in{"query"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"query"} and length $in{"query"}
defined $in{"query"} length $in{"query"}
Truth table0%0/3
A and B
A= defined $in{"query"}B= length $in{"query"}
ABresult
0X0
100
111
823 0 die("A query is needed for the query() method.");
824 }
825 0 ▶ if ( !defined $in{'limit'} || $in{'limit'} !~ m/^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"limit"} and $in{"limit"} =~ /^\d+$/) 0 0 0
Condition0%0/3
defined $in{"limit"} and $in{"limit"} =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"limit"} and $in{"limit"} =~ /^\d+$/
defined $in{"limit"} $in{"limit"} =~ /^\d+$/
Truth table0%0/3
A and B
A= defined $in{"limit"}B= $in{"limit"} =~ /^\d+$/
ABresult
0X0
100
111
826 0 $in{'limit'} = 500;
827 }
828 0 ▶ if ( $in{'limit'} < 1 || $in{'limit'} > 2000 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in{"limit"} < 1 or $in{"limit"} > 2000) 0 0 0
Condition0%0/3
$in{"limit"} < 1 or $in{"limit"} > 2000
l!l&&r!l&&!r
000
MC/DC0%0/2
$in{"limit"} < 1 or $in{"limit"} > 2000
$in{"limit"} < 1 $in{"limit"} > 2000
Truth table0%0/3
A or B
A= $in{"limit"} < 1B= $in{"limit"} > 2000
ABresult
1X1
011
000
829 0 die("A query's limit cannot exceed 2000. 500 is default.");
830 }
831  
832 my $limit = SOAP::Header->name(
833 0 'QueryOptions' => \SOAP::Header->name( 'batchSize' => $in{'limit'} ) )
834 ->prefix($SF_PREFIX)->uri($SF_URI);
835 0 my $client = $self->_get_client();
836 0 my $r = $client->queryAll( SOAP::Data->name( 'queryString' => $in{'query'} ),
837 $limit, $self->_get_session_header() );
838  
839 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
840 0 die "could not query " . $in{'query'};
841 }
842 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
843 0 die( $r->faultstring() );
844 }
845 0 return $r;
846 }
847  
848  
849 =head2 queryMore( HASH )
850  
851 Retrieves the next batch of objects from a C<query> or C<queryAll>.
852  
853 =over
854  
855 =item queryLocator
856  
857 The handle or string returned by C<query>. This identifies the result set and cursor for fetching the next set of rows from a result set.
858  
859 =item limit
860  
861 This sets the batch size, or size of the result returned. This is helpful in producing paginated results, or fetch small sets of data at a time.
862  
863 =back
864  
865 =cut
866  
867 sub queryMore {
868 0 ▶ my $self = shift;
Subroutine queryMore: not called CC=9 SCAR=45.0
Pod documented
869 0 my (%in) = @_;
870 0 ▶ if ( !defined $in{'queryLocator'} || !length $in{'queryLocator'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"queryLocator"} and length $in{"queryLocator"}) 0 0 0
Condition0%0/3
defined $in{"queryLocator"} and length $in{"queryLocator"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"queryLocator"} and length $in{"queryLocator"}
defined $in{"queryLocator"} length $in{"queryLocator"}
Truth table0%0/3
A and B
A= defined $in{"queryLocator"}B= length $in{"queryLocator"}
ABresult
0X0
100
111
871 0 die("A hash expected with key 'queryLocator'");
872 }
873 $in{'limit'} = 500
874 0 ▶ if ( !defined $in{'limit'} || $in{'limit'} !~ m/^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in{"limit"} and $in{"limit"} =~ /^\d+$/ 0 0 0
Condition0%0/3
defined $in{"limit"} and $in{"limit"} =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"limit"} and $in{"limit"} =~ /^\d+$/
defined $in{"limit"} $in{"limit"} =~ /^\d+$/
Truth table0%0/3
A and B
A= defined $in{"limit"}B= $in{"limit"} =~ /^\d+$/
ABresult
0X0
100
111
875 0 ▶ if ( $in{'limit'} < 1 || $in{'limit'} > 2000 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in{"limit"} < 1 or $in{"limit"} > 2000) 0 0 0
Condition0%0/3
$in{"limit"} < 1 or $in{"limit"} > 2000
l!l&&r!l&&!r
000
MC/DC0%0/2
$in{"limit"} < 1 or $in{"limit"} > 2000
$in{"limit"} < 1 $in{"limit"} > 2000
Truth table0%0/3
A or B
A= $in{"limit"} < 1B= $in{"limit"} > 2000
ABresult
1X1
011
000
876 0 die("A query's limit cannot exceed 2000. 500 is default.");
877 }
878  
879 my $limit = SOAP::Header->name(
880 0 'QueryOptions' => \SOAP::Header->name( 'batchSize' => $in{'limit'} ) )
881 ->prefix($SF_PREFIX)->uri($SF_URI);
882 0 my $client = $self->_get_client();
883 my $r = $client->queryMore(
884 0 SOAP::Data->name( 'queryLocator' => $in{'queryLocator'} ),
885 $limit, $self->_get_session_header() );
886  
887 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
888 0 die "could not queryMore " . $in{'queryLocator'};
889 }
890  
891 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
892 0 die( $r->faultstring() );
893 }
894 0 return $r;
895 }
896  
897 =head2 resetPassword( HASH )
898  
899 Changes a user's password to a server-generated value.
900  
901 =over
902  
903 =item userId
904  
905 A user Id.
906  
907 =back
908  
909 =cut
910  
911 sub resetPassword {
912 0 ▶ my $self = shift;
Subroutine resetPassword: not called CC=5 SCAR=34.0
Pod documented
913 0 my (%in) = @_;
914  
915 0 ▶ if ( !defined $in{'userId'} || !length $in{'userId'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"userId"} and length $in{"userId"}) 0 0 0
Condition0%0/3
defined $in{"userId"} and length $in{"userId"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"userId"} and length $in{"userId"}
defined $in{"userId"} length $in{"userId"}
Truth table0%0/3
A and B
A= defined $in{"userId"}B= length $in{"userId"}
ABresult
0X0
100
111
916 0 die("A hash expected with key 'userId'");
917 }
918  
919 0 my $client = $self->_get_client(1);
920 0 my $method =
921 SOAP::Data->name("resetPassword")->prefix($SF_PREFIX)->uri($SF_URI);
922 my $r = $client->call(
923 $method =>
924 0 SOAP::Data->prefix($SF_PREFIX)->name( 'userId' => $in{'userId'} )
925 ->type('xsd:string'),
926 $self->_get_session_header()
927 );
928  
929 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
930 0 die "could not call method $method";
931 }
932 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
933 0 die( $r->faultstring() );
934 }
935 0 return $r;
936 }
937  
938 =head2 retrieve( HASH )
939  
940 =over
941  
942 =item fields
943  
944 A comma delimited list of field name you want retrieved.
945  
946 =item type
947  
948 The type of the object being queried.
949  
950 =item ids
951  
952 The ids (LIST) of the object you want returned.
953  
954 =back
955  
956 =cut
957  
958 sub retrieve {
959 0 ▶ my $self = shift;
Subroutine retrieve: not called CC=14 SCAR=53.5
Pod documented
960 0 my (%in) = @_;
961  
962 $in{'limit'} = 500
963 0 ▶ if ( !defined $in{'limit'} || $in{'limit'} !~ m/^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in{"limit"} and $in{"limit"} =~ /^\d+$/ 0 0 0
Condition0%0/3
defined $in{"limit"} and $in{"limit"} =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"limit"} and $in{"limit"} =~ /^\d+$/
defined $in{"limit"} $in{"limit"} =~ /^\d+$/
Truth table0%0/3
A and B
A= defined $in{"limit"}B= $in{"limit"} =~ /^\d+$/
ABresult
0X0
100
111
964 0 ▶ if ( $in{'limit'} < 1 || $in{'limit'} > 2000 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in{"limit"} < 1 or $in{"limit"} > 2000) 0 0 0
Condition0%0/3
$in{"limit"} < 1 or $in{"limit"} > 2000
l!l&&r!l&&!r
000
MC/DC0%0/2
$in{"limit"} < 1 or $in{"limit"} > 2000
$in{"limit"} < 1 $in{"limit"} > 2000
Truth table0%0/3
A or B
A= $in{"limit"} < 1B= $in{"limit"} > 2000
ABresult
1X1
011
000
965 0 die("A query's limit cannot exceed 2000. 500 is default.");
966 }
967 0 ▶ if ( !defined $in{'fields'} || !length $in{'fields'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"fields"} and length $in{"fields"}) 0 0 0
Condition0%0/3
defined $in{"fields"} and length $in{"fields"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"fields"} and length $in{"fields"}
defined $in{"fields"} length $in{"fields"}
Truth table0%0/3
A and B
A= defined $in{"fields"}B= length $in{"fields"}
ABresult
0X0
100
111
968 0 die("Hash with key 'fields' expected.");
969 }
970 0 ▶ if ( !defined $in{'ids'} || !length $in{'ids'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"ids"} and length $in{"ids"}) 0 0 0
Condition0%0/3
defined $in{"ids"} and length $in{"ids"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"ids"} and length $in{"ids"}
defined $in{"ids"} length $in{"ids"}
Truth table0%0/3
A and B
A= defined $in{"ids"}B= length $in{"ids"}
ABresult
0X0
100
111
971 0 die("Hash with key 'ids' expected.");
972 }
973 0 ▶ if ( !defined $in{'type'} || !length $in{'type'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"type"} and length $in{"type"}) 0 0 0
Condition0%0/3
defined $in{"type"} and length $in{"type"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"type"} and length $in{"type"}
defined $in{"type"} length $in{"type"}
Truth table0%0/3
A and B
A= defined $in{"type"}B= length $in{"type"}
ABresult
0X0
100
111
974 0 die("Hash with key 'type' expected.");
975 }
976  
977 0 my @elems;
978 0 my $client = $self->_get_client(1);
979 0 my $method = SOAP::Data->name("retrieve")->prefix($SF_PREFIX)->uri($SF_URI);
980 0 foreach my $id ( @{ $in{'ids'} } ) {
981 0 push( @elems,
982 SOAP::Data->prefix($SF_PREFIX)->name( 'ids' => $id )
983 ->type('xsd:string') );
984 }
985 my $r = $client->call(
986 $method =>
987 SOAP::Data->prefix($SF_PREFIX)->name( 'fieldList' => $in{'fields'} )
988 ->type('xsd:string'),
989 0 SOAP::Data->prefix($SF_PREFIX)->name( 'sObjectType' => $in{'type'} )
990 ->type('xsd:string'),
991 @elems,
992 $self->_get_session_header()
993 );
994  
995 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
996 0 die "could not call method $method";
997 }
998 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
999 0 die( $r->faultstring() );
1000 }
1001 0 return $r;
1002 }
1003  
1004  
1005 =head2 search( HASH )
1006  
1007 =over
1008  
1009 =item searchString
1010  
1011 The search string to be used in the query. For example,
1012 C<< find {4159017000} in phone fields returning contact(id, phone, firstname, lastname), lead(id, phone, firstname, lastname), account(id, phone, name) >>
1013  
1014 =back
1015  
1016 =cut
1017  
1018 sub search {
1019 0 ▶ my $self = shift;
Subroutine search: not called CC=5 SCAR=34.0
Pod documented
1020 0 my (%in) = @_;
1021  
1022 0 ▶ if ( !defined $in{'searchString'} || !length $in{'searchString'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"searchString"} and length $in{"searchString"}) 0 0 0
Condition0%0/3
defined $in{"searchString"} and length $in{"searchString"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"searchString"} and length $in{"searchString"}
defined $in{"searchString"} length $in{"searchString"}
Truth table0%0/3
A and B
A= defined $in{"searchString"}B= length $in{"searchString"}
ABresult
0X0
100
111
1023 0 die("Expected hash with key 'searchString'");
1024 }
1025 0 my $client = $self->_get_client(1);
1026 0 my $method = SOAP::Data->name("search")->prefix($SF_PREFIX)->uri($SF_URI);
1027 my $r = $client->call(
1028 $method => SOAP::Data->prefix($SF_PREFIX)
1029 0 ->name( 'searchString' => $in{'searchString'} )->type('xsd:string'),
1030 $self->_get_session_header()
1031 );
1032  
1033 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
1034 0 die "could not search with " . $in{'searchString'};
1035 }
1036 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
1037 0 die( $r->faultstring() );
1038 }
1039 0 return $r;
1040 }
1041  
1042  
1043 =head2 setPassword( HASH )
1044  
1045 Sets the specified user's password to the specified value.
1046  
1047 =over
1048  
1049 =item userId
1050  
1051 A user Id.
1052  
1053 =item password
1054  
1055 The new password to assign to the user identified by C<userId>.
1056  
1057 =back
1058  
1059 =cut
1060  
1061 sub setPassword {
1062 0 ▶ my $self = shift;
Subroutine setPassword: not called CC=7 SCAR=40.3
Pod documented
1063 0 my (%in) = @_;
1064  
1065 0 ▶ if ( !defined $in{'userId'} || !length $in{'userId'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"userId"} and length $in{"userId"}) 0 0 0
Condition0%0/3
defined $in{"userId"} and length $in{"userId"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"userId"} and length $in{"userId"}
defined $in{"userId"} length $in{"userId"}
Truth table0%0/3
A and B
A= defined $in{"userId"}B= length $in{"userId"}
ABresult
0X0
100
111
1066 0 die("Expected a hash with key 'userId'");
1067 }
1068 0 ▶ if ( !defined $in{'password'} || !length $in{'password'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in{"password"} and length $in{"password"}) 0 0 0
Condition0%0/3
defined $in{"password"} and length $in{"password"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $in{"password"} and length $in{"password"}
defined $in{"password"} length $in{"password"}
Truth table0%0/3
A and B
A= defined $in{"password"}B= length $in{"password"}
ABresult
0X0
100
111
1069 0 die("Expected a hash with key 'password'");
1070 }
1071  
1072 0 my $client = $self->_get_client(1);
1073 0 my $method =
1074 SOAP::Data->name("setPassword")->prefix($SF_PREFIX)->uri($SF_URI);
1075 my $r = $client->call(
1076 $method =>
1077 SOAP::Data->prefix($SF_PREFIX)->name( 'userId' => $in{'userId'} )
1078 ->type('xsd:string'),
1079 0 SOAP::Data->prefix($SF_PREFIX)->name( 'password' => $in{'password'} )
1080 ->type('xsd:string'),
1081 $self->_get_session_header()
1082 );
1083  
1084 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
1085 0 die "could not call method $method";
1086 }
1087 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
1088 0 die( $r->faultstring() );
1089 }
1090 0 return $r;
1091 }
1092  
1093  
1094 =head2 sf_date
1095  
1096 Converts a time in Epoch seconds to the date format that Salesforce likes
1097  
1098 =cut
1099  
1100 sub sf_date {
1101 0 ▶ my $self = shift;
Subroutine sf_date: not called CC=2 SCAR=17.9
Pod documented
1102 0 ▶ my $secs = shift || time;
Condition0%0/3
shift() || time
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || time
shift() time
Truth table0%0/3
A || B
A= shift()B= time
ABresult
1X1
011
000
1103 0 my $dt = DateTime->from_epoch(epoch=>$secs);
1104 0 $dt->set_time_zone('local');
1105 0 return $dt->strftime(q(%FT%T.%3N%z));
1106 }
1107  
1108  
1109 =head2 update(type => $type, HASHREF [, HASHREF ...])
1110  
1111 Updates one or more existing objects in your organization's data. This subroutine takes as input a B<type> value which names the type of object to update (e.g. Account, User) and one or more perl HASH references containing the fields (the keys of the hash) and the values of the record that will be updated.
1112  
1113 The hash must contain the 'Id' key in order to identify the record to update.
1114  
1115 =cut
1116  
1117 sub update {
1118 0 ▶ my $self = shift;
Subroutine update: not called CC=11 SCAR=48.8
Pod documented
1119  
1120 0 my ( $spec, $type ) = splice @_, 0, 2;
1121 0 ▶ if ( $spec ne 'type' || !$type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec ne "type" or not $type) 0 0 0
Condition0%0/3
$spec ne "type" or not $type
l!l&&r!l&&!r
000
MC/DC0%0/2
$spec ne "type" or not $type
$spec ne "type" not $type
Truth table0%0/3
A or not(B)
A= $spec ne "type"B= not $type
ABresult
1X1
011
000
1122 0 die("Expected a hash with key 'type' as first argument");
1123 }
1124  
1125 0 my %tmp = ();
1126 0 my @sobjects = @_;
1127 0 ▶ if ( ref $sobjects[0] ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sobjects[0] ne "HASH") 0 0 0
1128 0 %tmp = @_;
1129 0 @sobjects = ( \%tmp ); # create an array of one
1130 }
1131  
1132 0 my @updates;
1133 0 foreach (@sobjects) { # arg list is now an array of hash refs
1134 0 my %in = %{$_};
1135  
1136 0 my $id = $in{'id'};
1137 0 delete( $in{'id'} );
1138 0 ▶ if ( !$id ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id) 0 0 0
1139 0 die("Expected a hash with key 'id'");
1140 }
1141  
1142 0 my @elems;
1143 my @fieldsToNull;
1144 0 push @elems,
1145 SOAP::Data->prefix($SF_PREFIX)->name( 'Id' => $id )
1146 ->type('sforce:ID');
1147 0 foreach my $key ( keys %in ) {
1148 0 ▶ if ( !defined $in{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $in{$key}) { } 0 0 0
1149 0 push @fieldsToNull, $key;
1150 }
1151 else {
1152 push @elems,
1153 0 SOAP::Data->prefix($SF_PREFIX)->name( $key => $in{$key} )
1154 ->type( WWW::Salesforce::Constants->type( $type, $key ) );
1155 }
1156 }
1157 0 for my $key ( @fieldsToNull ) {
1158 0 push @elems,
1159 SOAP::Data->prefix($SF_PREFIX)->name( fieldsToNull => $key )
1160 ->type( 'xsd:string' );
1161 }
1162 0 push @updates,
1163 SOAP::Data->name( 'sObjects' => \SOAP::Data->value(@elems) )
1164 ->attr( { 'xsi:type' => 'sforce:' . $type } );
1165 }
1166  
1167 0 my $client = $self->_get_client(1);
1168 0 my $method =
1169 SOAP::Data->name("update")->prefix($SF_PREFIX)->uri($SF_URI)
1170 ->attr( { 'xmlns:sfons' => $SF_SOBJECT_URI } );
1171 0 my $r = $client->call(
1172 $method => $self->_get_session_header(),
1173 @updates
1174 );
1175 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
1176 0 die "could not call method $method";
1177 }
1178 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
1179 0 die( $r->faultstring() );
1180 }
1181 0 return $r;
1182 }
1183  
1184  
1185 =head2 upsert(type => $type, key => $key, HASHREF [, HASHREF ...])
1186  
1187 Updates or inserts one or more objects in your organization's data. If the data doesn't exist on Salesforce, it will be inserted. If it already exists it will be updated.
1188  
1189 This subroutine takes as input a B<type> value which names the type of object to update (e.g. Account, User). It also takes a B<key> value which specifies the unique key Salesforce should use to determine if it needs to update or insert. If B<key> is not given it will default to 'Id' which is Salesforce's own internal unique ID. This key can be any of Salesforce's default fields or an custom field marked as an external key.
1190  
1191 Finally, this method takes one or more perl HASH references containing the fields (the keys of the hash) and the values of the record that will be updated.
1192  
1193 =cut
1194  
1195 sub upsert {
1196 0 ▶ my $self = shift;
Subroutine upsert: not called CC=11 SCAR=48.8
Pod documented
1197 0 my ( $spec, $type, $extern, $name, @sobjects ) = @_;
1198  
1199 0 ▶ if ( $spec ne 'type' || !$type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec ne "type" or not $type) 0 0 0
Condition0%0/3
$spec ne "type" or not $type
l!l&&r!l&&!r
000
MC/DC0%0/2
$spec ne "type" or not $type
$spec ne "type" not $type
Truth table0%0/3
A or not(B)
A= $spec ne "type"B= not $type
ABresult
1X1
011
000
1200 0 die("Expected a hash with key 'type' as first argument");
1201 }
1202  
1203 # Default to the 'id' field
1204 0 ▶ $name ||= 'id';
Condition0%0/2
$name ||= "id"
l!l
00
MC/DC0%0/1
$name ||= "id"
$name
Truth table0%0/2
A
A= $name
Aresult
11
00
1205  
1206 0 my %tmp = ();
1207 0 ▶ if ( ref $sobjects[0] ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sobjects[0] ne "HASH") 0 0 0
1208 0 %tmp = @_;
1209 0 @sobjects = ( \%tmp ); # create an array of one
1210 }
1211  
1212 0 my @updates =
1213 ( SOAP::Data->prefix($SF_PREFIX)->name( 'externalIDFieldName' => $name )
1214 ->attr( { 'xsi:type' => 'xsd:string' } ) );
1215  
1216 0 foreach (@sobjects) { # arg list is now an array of hash refs
1217 0 my %in = %{$_};
1218  
1219 0 my @elems;
1220 my @fieldsToNull;
1221 0 foreach my $key ( keys %in ) {
1222 0 ▶ if ( !defined $in{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $in{$key}) { } 0 0 0
1223 0 push @fieldsToNull, $key;
1224 }
1225 else {
1226 push @elems,
1227 0 SOAP::Data->prefix($SF_PREFIX)->name( $key => $in{$key} )
1228 ->type( WWW::Salesforce::Constants->type( $type, $key ) );
1229 }
1230 }
1231 0 for my $key ( @fieldsToNull ) {
1232 0 push @elems,
1233 SOAP::Data->prefix($SF_PREFIX)->name( fieldsToNull => $key )
1234 ->type( 'xsd:string' );
1235 }
1236 0 push @updates,
1237 SOAP::Data->name( 'sObjects' => \SOAP::Data->value(@elems) )
1238 ->attr( { 'xsi:type' => 'sforce:' . $type } );
1239 }
1240  
1241 0 my $client = $self->_get_client(1);
1242 0 my $method =
1243 SOAP::Data->name("upsert")->prefix($SF_PREFIX)->uri($SF_URI)
1244 ->attr( { 'xmlns:sfons' => $SF_SOBJECT_URI } );
1245 0 my $r = $client->call(
1246 $method => $self->_get_session_header(),
1247 @updates
1248 );
1249 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
1250 0 die "could not call method $method";
1251 }
1252 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
1253 0 die( $r->faultstring() );
1254 }
1255 0 return $r;
1256 }
1257  
1258 # TODO: remove in version 0.400
1259 sub get_clientM {
1260 0 ▶ warn "The method: get_clientM() has always been private. It is now deprecated and will be removed in version 0.400.";
Subroutine get_clientM: not called CC=1 SCAR=6.9
Pod undocumented
1261 0 return shift->_get_client_meta(@_);
1262 }
1263  
1264 # TODO: remove in version 0.400
1265 sub get_session_headerM {
1266 0 ▶ warn "The method: get_session_headerM() has always been private. It is now deprecated and will be removed in version 0.400.";
Subroutine get_session_headerM: not called CC=1 SCAR=6.9
Pod undocumented
1267 0 return shift->_get_session_header_meta(@_);
1268 }
1269  
1270 =head2 describeMetadata()
1271  
1272 Get some metadata info about your instance.
1273  
1274 =cut
1275  
1276 sub describeMetadata {
1277 0 ▶ my $self = shift;
Subroutine describeMetadata: not called CC=3 SCAR=24.8
Pod documented
1278 0 my $client = $self->_get_client_meta(1);
1279 0 my $method =
1280 SOAP::Data->name("describeMetadata")->prefix($SF_PREFIX)->uri($SF_URIM);
1281  
1282 my $r = $client->call(
1283 $method =>
1284 0 SOAP::Data->prefix($SF_PREFIX)->name( 'asOfVersion' )->value( $self->{sf_version} ), $self->_get_session_header_meta() );
1285 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
1286 0 die "could not call method $method";
1287 }
1288 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
1289 0 die( $r->faultstring() );
1290 }
1291 0 return $r->valueof('//describeMetadataResponse/result');
1292 }
1293  
1294  
1295 =head2 retrieveMetadata
1296  
1297 =cut
1298  
1299 sub retrieveMetadata {
1300 0 ▶ my $self = shift;
Subroutine retrieveMetadata: not called CC=4 SCAR=30.0
Pod documented
1301 0 my %list = @_;
1302 0 my @req;
1303 0 foreach my $i (keys %list) {
1304 push(
1305 @req,
1306 SOAP::Data->name(
1307 'types' => \SOAP::Data->value(
1308 0 SOAP::Data->name('members' => $list{$i}),
1309 SOAP::Data->name('name' => $i)
1310 )
1311 )
1312 );
1313 }
1314 0 my $client = $self->_get_client_meta(1);
1315 0 my $method = SOAP::Data->name('retrieve')->prefix($SF_PREFIX)->uri($SF_URIM);
1316 my $r = $client->call(
1317 $method,
1318 $self->_get_session_header_meta(),
1319 SOAP::Data->name('retrieveRequest' => \SOAP::Data->value(
1320 SOAP::Data->name('apiVersion' => $self->{sf_version}),
1321 SOAP::Data->name('singlePackage' => 'true'),
1322 SOAP::Data->name('unpackaged' => \SOAP::Data->value(
1323 @req,
1324 SOAP::Data->name('version' => $self->{sf_version})
1325 0 ))
1326 ))
1327 );
1328 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
1329 0 die "could not call method $method";
1330 }
1331 0 ▶ if ($r->fault()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
1332 0 die($r->faultstring());
1333 }
1334 0 $r = $r->valueof('//retrieveResponse/result');
1335 0 return $r;
1336 }
1337  
1338  
1339 =head2 checkAsyncStatus( $pid )
1340  
1341 =cut
1342  
1343 sub checkAsyncStatus {
1344 0 ▶ my $self = shift;
Subroutine checkAsyncStatus: not called CC=6 SCAR=37.4
Pod documented
1345 0 my $pid = shift;
1346 #print "JOB - ID $pid\n";
1347 0 my $client = $self->_get_client_meta(1);
1348 0 my $method = SOAP::Data->name('checkStatus')->prefix($SF_PREFIX)->uri($SF_URIM);
1349 0 my $r;
1350 0 my $waitTimeMilliSecs = 1;
1351 0 my $Count =1 ;
1352 0 my $MAX_NUM_POLL_REQUESTS = 50;
1353 0 while (1) {
1354 0 sleep($waitTimeMilliSecs);
1355 0 $waitTimeMilliSecs *=2;
1356 0 $r = $client->call(
1357 $method,
1358 SOAP::Data->name('asyncProcessId'=>$pid)->type('xsd:ID'),
1359 $self->_get_session_header_meta()
1360 );
1361 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
1362 0 die "could not call method $method";
1363 }
1364 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
1365 0 die( $r->faultstring() );
1366 }
1367 0 $r = $r->valueof('//checkStatusResponse/result');
1368 0 ▶ last if ($r->{'done'} eq 'true' || $Count >$MAX_NUM_POLL_REQUESTS);
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"done"} eq "true" or $Count > $MAX_NUM_POLL_REQUESTS 0 0 0
Condition0%0/3
$r->{"done"} eq "true" or $Count > $MAX_NUM_POLL_REQUESTS
l!l&&r!l&&!r
000
MC/DC0%0/2
$r->{"done"} eq "true" or $Count > $MAX_NUM_POLL_REQUESTS
$r->{"done"} eq "true" $Count > $MAX_NUM_POLL_REQUESTS
Truth table0%0/3
A or B
A= $r->{"done"} eq "true"B= $Count > $MAX_NUM_POLL_REQUESTS
ABresult
1X1
011
000
1369 0 $Count++;
1370 }
1371 0 ▶ if ($r->{'done'} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"done"} eq "true") 0 0 0
1372 0 return $self->checkRetrieveStatus($r->{'id'});
1373 }
1374 0 return;
1375 }
1376  
1377  
1378 =head2 checkRetrieveStatus( $pid )
1379  
1380 =cut
1381  
1382 sub checkRetrieveStatus {
1383 0 ▶ my $self = shift;
Subroutine checkRetrieveStatus: not called CC=3 SCAR=24.8
Pod documented
1384 0 my $pid = shift;
1385 0 my $client = $self->_get_client_meta(1);
1386 0 my $method = SOAP::Data->name('checkRetrieveStatus')->prefix($SF_PREFIX)->uri($SF_URIM);
1387  
1388 0 my $r = $client->call(
1389 $method,
1390 SOAP::Data->name('asyncProcessId'=>$pid),
1391 $self->_get_session_header_meta()
1392 );
1393 0 ▶ unless ($r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
1394 0 die "could not call method $method";
1395 }
1396 0 ▶ if ( $r->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->fault) 0 0 0
1397 0 die( $r->faultstring() );
1398 }
1399 0 return $r->valueof('//checkRetrieveStatusResponse/result');
1400 }
1401  
1402  
1403 =head2 getErrorDetails( RESULT )
1404  
1405 Returns a hash with information about errors from API calls - only useful if ($res->valueof('//success') ne 'true')
1406  
1407 {
1408 'statusCode' => 'INVALID_FIELD_FOR_INSERT_UPDATE',
1409 'message' => 'Account: bad field names on insert/update call: type'
1410 ...
1411 }
1412  
1413 =cut
1414  
1415 sub getErrorDetails {
1416 0 ▶ my $self = shift;
Subroutine getErrorDetails: not called CC=1 SCAR=6.9
Pod documented
1417 0 my $result = shift;
1418 0 return $result->valueof('//errors');
1419 }
1420  
1421  
1422 =head2 bye()
1423  
1424 Synonym for C<logout>.
1425  
1426 Ends the session for the logged-in user issuing the call. No arguments are needed.
1427 Returns a reference to an array of hash refs
1428  
1429 =cut
1430  
1431 sub bye {
1432 0 ▶ my ( $self ) = @_;
Subroutine bye: not called CC=2 SCAR=17.9
Pod documented
1433 0 ▶ $self->logout() or die 'could not logout';
Branch: 1 branch
BranchTrueFalseTotal
$self->logout or die "could not logout" 0 0 0
1434 }
1435  
1436  
1437 =head2 do_query( $query, [$limit] )
1438  
1439 Returns a reference to an array of hash refs
1440  
1441 =cut
1442  
1443 sub do_query {
1444 0 ▶ my ( $self, $query, $limit ) = @_;
Subroutine do_query: not called CC=11 SCAR=48.8
Pod documented
1445  
1446 0 ▶ if ( !defined $query || $query !~ m/^select/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $query and $query =~ /^select/i) 0 0 0
Condition0%0/3
defined $query and $query =~ /^select/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $query and $query =~ /^select/i
defined $query $query =~ /^select/i
Truth table0%0/3
A and B
A= defined $queryB= $query =~ /^select/i
ABresult
0X0
100
111
1447 0 die('Param1 of do_query() should be a string SQL query');
1448 }
1449  
1450 0 ▶ $limit = 2000
Branch: 1 branch
BranchTrueFalseTotal
unless defined $limit and $limit =~ /^\d+$/ and $limit > 0 and $limit < 2001 0 0 0
Condition0%0/9
defined $limit and $limit =~ /^\d+$/ and $limit > 0 and $limit < 2001
!ll&&!rl&&r
000
defined $limit and $limit =~ /^\d+$/ and $limit > 0
!ll&&!rl&&r
000
defined $limit and $limit =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/4
defined $limit and $limit =~ /^\d+$/ and $limit > 0 and $limit < 2001
defined $limit $limit =~ /^\d+$/ $limit > 0 $limit < 2001
Truth table0%0/5
A and B and C and D
A= defined $limitB= $limit =~ /^\d+$/C= $limit > 0D= $limit < 2001
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1451 unless defined $limit
1452 and $limit =~ m/^\d+$/
1453 and $limit > 0
1454 and $limit < 2001;
1455  
1456 0 my @rows = (); #to be returned
1457  
1458 0 my $res = $self->query( query => $query, limit => $limit );
1459 0 ▶ unless ($res) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res) 0 0 0
1460 0 die "could not execute query $query, limit $limit";
1461 }
1462 0 ▶ if ( $res->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->fault) 0 0 0
1463 0 die( $res->faultstring() );
1464 }
1465  
1466 0 ▶ push @rows, $res->valueof('//queryResponse/result/records')
Branch: 1 branch
BranchTrueFalseTotal
if $res->valueof("//queryResponse/result/size") > 0 0 0 0
1467 if ( $res->valueof('//queryResponse/result/size') > 0 );
1468  
1469 #we get the results in batches of 2,000... so continue getting them
1470 #if there are more to get
1471 0 my $done = $res->valueof('//queryResponse/result/done');
1472 0 my $ql = $res->valueof('//queryResponse/result/queryLocator');
1473 0 ▶ if ( $done eq 'false' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($done eq "false") 0 0 0
1474 0 push @rows, @{$self->_retrieve_queryMore($ql, $limit)};
1475 }
1476  
1477 0 return \@rows;
1478 }
1479  
1480  
1481 =head2 do_queryAll( $query, [$limit] )
1482  
1483 Returns a reference to an array of hash refs
1484  
1485 =cut
1486  
1487 sub do_queryAll {
1488 0 ▶ my ( $self, $query, $limit ) = @_;
Subroutine do_queryAll: not called CC=11 SCAR=48.8
Pod documented
1489  
1490 0 ▶ if ( !defined $query || $query !~ m/^select/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $query and $query =~ /^select/i) 0 0 0
Condition0%0/3
defined $query and $query =~ /^select/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $query and $query =~ /^select/i
defined $query $query =~ /^select/i
Truth table0%0/3
A and B
A= defined $queryB= $query =~ /^select/i
ABresult
0X0
100
111
1491 0 die('Param1 of do_queryAll() should be a string SQL query');
1492 }
1493  
1494 0 ▶ $limit = 2000
Branch: 1 branch
BranchTrueFalseTotal
unless defined $limit and $limit =~ /^\d+$/ and $limit > 0 and $limit < 2001 0 0 0
Condition0%0/9
defined $limit and $limit =~ /^\d+$/ and $limit > 0 and $limit < 2001
!ll&&!rl&&r
000
defined $limit and $limit =~ /^\d+$/ and $limit > 0
!ll&&!rl&&r
000
defined $limit and $limit =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/4
defined $limit and $limit =~ /^\d+$/ and $limit > 0 and $limit < 2001
defined $limit $limit =~ /^\d+$/ $limit > 0 $limit < 2001
Truth table0%0/5
A and B and C and D
A= defined $limitB= $limit =~ /^\d+$/C= $limit > 0D= $limit < 2001
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1495 unless defined $limit
1496 and $limit =~ m/^\d+$/
1497 and $limit > 0
1498 and $limit < 2001;
1499  
1500 0 my @rows = (); #to be returned
1501  
1502 0 my $res = $self->queryAll( query => $query, limit => $limit );
1503 0 ▶ unless ($res) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res) 0 0 0
1504 0 die "could not execute query $query, limit $limit";
1505 }
1506 0 ▶ if ( $res->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->fault) 0 0 0
1507 0 die( $res->faultstring() );
1508 }
1509  
1510 0 ▶ push @rows, $res->valueof('//queryAllResponse/result/records')
Branch: 1 branch
BranchTrueFalseTotal
if $res->valueof("//queryAllResponse/result/size") > 0 0 0 0
1511 if ( $res->valueof('//queryAllResponse/result/size') > 0 );
1512  
1513 #we get the results in batches of 2,000... so continue getting them
1514 #if there are more to get
1515 0 my $done = $res->valueof('//queryAllResponse/result/done');
1516 0 my $ql = $res->valueof('//queryAllResponse/result/queryLocator');
1517 0 ▶ if ( $done eq 'false' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($done eq "false") 0 0 0
1518 0 push @rows, @{$self->_retrieve_queryMore($ql, $limit)};
1519 }
1520  
1521 0 return \@rows;
1522 }
1523  
1524 #**************************************************************************
1525 # _retrieve_queryMore
1526 # -- returns the next block of a running query set. Supports do_query
1527 # and do_queryAll
1528 #
1529 #**************************************************************************
1530  
1531 sub _retrieve_queryMore {
1532 0 ▶ my ( $self, $ql, $limit ) = @_;
Subroutine _retrieve_queryMore: not called CC=5 SCAR=34.0
1533  
1534 0 my $done = 'false';
1535 0 my @results;
1536  
1537 0 ▶ while ($done eq 'false') {
Branch: 1 branch
BranchTrueFalseTotal
if ($done eq "false") 0 0 0
1538 0 my $res = $self->queryMore(
1539 queryLocator => $ql,
1540 limit => $limit
1541 );
1542 0 ▶ unless ($res) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res) 0 0 0
1543 0 die "could not execute queryMore $ql, limit $limit";
1544 }
1545 0 ▶ if ( $res->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->fault) 0 0 0
1546 0 die( $res->faultstring() );
1547 }
1548 0 $done = $res->valueof('//queryMoreResponse/result/done');
1549 0 $ql = $res->valueof('//queryMoreResponse/result/queryLocator');
1550  
1551 0 ▶ if ( $res->valueof('//queryMoreResponse/result/size') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->valueof("//queryMoreResponse/result/size")) 0 0 0
1552 0 push @results, $res->valueof('//queryMoreResponse/result/records');
1553 }
1554 }
1555  
1556 0 return \@results;
1557  
1558 }
1559  
1560 =head2 get_field_list( $table_name )
1561  
1562 Returns a ref to an array of hash refs for each field name
1563 Field name keyed as 'name'
1564  
1565 =cut
1566  
1567 sub get_field_list {
1568 0 ▶ my ( $self, $table_name ) = @_;
Subroutine get_field_list: not called CC=5 SCAR=34.0
Pod documented
1569  
1570 0 ▶ if ( !defined $table_name || !length $table_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $table_name and length $table_name) 0 0 0
Condition0%0/3
defined $table_name and length $table_name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $table_name and length $table_name
defined $table_name length $table_name
Truth table0%0/3
A and B
A= defined $table_nameB= length $table_name
ABresult
0X0
100
111
1571 0 die('Param1 of get_field_list() should be a string');
1572 }
1573  
1574 0 my $res = $self->describeSObject( 'type' => $table_name );
1575 0 ▶ unless ($res) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res) 0 0 0
1576 0 die "could not describeSObject for table $table_name";
1577 }
1578 0 ▶ if ( $res->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->fault) 0 0 0
1579 0 die( $res->faultstring() );
1580 }
1581  
1582 0 my @fields = $res->valueof('//describeSObjectResponse/result/fields');
1583 0 return \@fields;
1584 }
1585  
1586  
1587 =head2 get_tables()
1588  
1589 Returns a reference to an array of hash references
1590 Each hash gives the properties for each Salesforce object
1591  
1592 =cut
1593  
1594 sub get_tables {
1595 0 ▶ my ($self) = @_;
Subroutine get_tables: not called CC=3 SCAR=24.8
Pod documented
1596  
1597 0 my $res = $self->describeGlobal();
1598 0 ▶ unless ($res) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res) 0 0 0
1599 0 die "could not describeGlobal()";
1600 }
1601 0 ▶ if ( $res->fault() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->fault) 0 0 0
1602 0 die( $res->faultstring() );
1603 }
1604  
1605 0 my @globals = $res->valueof('//describeGlobalResponse/result/sobjects');
1606 0 return \@globals;
1607 }
1608  
1609 # private methods
1610 sub _get_client {
1611 0 ▶ my $self = shift;
Subroutine _get_client: not called CC=3 SCAR=24.8
1612 0 my ($readable) = @_;
1613 0 ▶ $readable = ($readable) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$readable ? : 0 0 0
1614  
1615 my $client
1616 = SOAP::Lite->readable($readable)
1617 ->deserializer(WWW::Salesforce::Deserializer->new)
1618 ->serializer(WWW::Salesforce::Serializer->new)
1619 0 ▶ ->on_action(sub { return '""' })->uri($SF_URI)->multirefinplace(1);
Subroutine __ANON__: not called CC=1 SCAR=6.9
1620  
1621 0 ▶ if ($WEB_PROXY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WWW::Salesforce::WEB_PROXY) { } 0 0 0
1622 0 $client->proxy($self->{'sf_serverurl'},
1623 proxy => ['https' => $WEB_PROXY]);
1624 }
1625 else {
1626 0 $client->proxy($self->{'sf_serverurl'});
1627 }
1628 0 return $client;
1629 }
1630  
1631 sub _get_client_meta {
1632 0 ▶ my $self = shift;
Subroutine _get_client_meta: not called CC=2 SCAR=17.9
1633 0 my ($readable) = @_;
1634 0 ▶ $readable = ($readable) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$readable ? : 0 0 0
1635  
1636 my $client
1637 = SOAP::Lite->readable($readable)
1638 ->deserializer(WWW::Salesforce::Deserializer->new)
1639 ->serializer(WWW::Salesforce::Serializer->new)
1640 0 ▶ ->on_action(sub { return '""' })->uri($SF_URI)->multirefinplace(1)
Subroutine __ANON__: not called CC=1 SCAR=6.9
1641 0 ->proxy($self->{'sf_metadataServerUrl'})->soapversion('1.1');
1642 0 return $client;
1643 }
1644  
1645 sub _get_session_header {
1646 0 ▶ my ($self) = @_;
Subroutine _get_session_header: not called CC=1 SCAR=6.9
1647 return SOAP::Header->name('SessionHeader' =>
1648 0 \SOAP::Header->name('sessionId' => $self->{'sf_sid'}))
1649 ->uri($SF_URI)->prefix($SF_PREFIX);
1650 }
1651  
1652 sub _get_session_header_meta {
1653 0 ▶ my ($self) = @_;
Subroutine _get_session_header_meta: not called CC=1 SCAR=6.9
1654 return SOAP::Header->name( 'SessionHeader' =>
1655 0 \SOAP::Header->name( 'sessionId' => $self->{'sf_sid'} ) )
1656 ->uri($SF_URIM)->prefix($SF_PREFIX);
1657 }
1658  
1659  
1660 4 1;
1661 __END__
1662  
1663  
1664 =head1 EXAMPLES
1665  
1666 =head2 login()
1667  
1668 use WWW::Salesforce;
1669 my $sf = WWW::Salesforce->login( 'username' => $user,'password' => $pass )
1670 or die $@;
1671  
1672 =head2 search()
1673  
1674 my $query = 'find {4159017000} in phone fields returning contact(id, phone, ';
1675 $query .= 'firstname, lastname), lead(id, phone, firstname, lastname), ';
1676 $query .= 'account(id, phone, name)';
1677 my $result = $sforce->search( 'searchString' => $query );
1678  
1679 =head1 SUPPORT
1680  
1681 Please visit Salesforce.com's user/developer forums online for assistance with
1682 this module. You are free to contact the author directly if you are unable to
1683 resolve your issue online.
1684  
1685 =head1 CAVEATS
1686  
1687 The C<describeSObjects> and C<describeTabs> API calls are not yet complete. These will be
1688 completed in future releases.
1689  
1690 Not enough test cases built into the install yet. More to be added.
1691  
1692 =head1 SEE ALSO
1693  
1694 L<DBD::Salesforce> by Jun Shimizu
1695 L<SOAP::Lite> by Byrne Reese
1696  
1697 Examples on Salesforce website:
1698 L<http://www.sforce.com/us/docs/sforce70/wwhelp/wwhimpl/js/html/wwhelp.htm>
1699  
1700 =head1 HISTORY
1701  
1702 This Perl module was originally provided and presented as part of
1703 the first Salesforce.com dreamForce conference on Nov. 11, 2003 in
1704 San Francisco.
1705  
1706 =head1 AUTHORS
1707  
1708 Byrne Reese - <byrne at majordojo dot com>
1709  
1710 Chase Whitener <F<capoeirab@cpan.org>>
1711  
1712 Fred Moyer <fred at redhotpenguin dot com>
1713  
1714 =head1 CONTRIBUTORS
1715  
1716 Michael Blanco
1717  
1718 Garth Webb
1719  
1720 Jun Shimizu
1721  
1722 Ron Hess
1723  
1724 Tony Stubblebine
1725  
1726 =head1 COPYRIGHT & LICENSE
1727  
1728 Copyright 2003-2004 Byrne Reese, Chase Whitener, Fred Moyer. All rights reserved.
1729  
1730 This program is free software; you can redistribute it and/or modify it
1731 under the same terms as Perl itself.
1732  
1733 =cut
↑ Summary Salesforce/Deserializer.pm »