Salesforce.pm

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