Skip to content

Commit

Permalink
Add createHdr() method which allows a header to be passed to the
Browse files Browse the repository at this point in the history
Salesforce create API.
  • Loading branch information
Don Lewis committed Jun 27, 2018
1 parent 35089b4 commit 9ea48d0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ The following are the accepted input parameters:
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.
The hash must contain the 'type' key in order to identify the type of the record to add.

Returns a SOAP::Lite object. Success of this operation can be gleaned from
the envelope result.

$r->envelope->{Body}->{createResponse}->{result}->{success};

## createHdr( header, HASH )

Adds one new individual objects to your organization's data with the specfied header. This takes as input the header and a HASH containing the fields (the keys of the hash) and the values of the record you wish to add to your organization.
The hash must contain the 'type' key in order to identify the type of the record to add.

Returns a SOAP::Lite object. Success of this operation can be gleaned from
the envelope result.

Expand Down
51 changes: 51 additions & 0 deletions lib/WWW/Salesforce.pm
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,57 @@ sub create {
}


=head2 createHdr( header, HASH )
Adds one new individual objects to your organization's data with the specfied header. This takes as input the header and a HASH containing the fields (the keys of the hash) and the values of the record you wish to add to your organization.
The hash must contain the 'type' key in order to identify the type of the record to add.
Returns a SOAP::Lite object. Success of this operation can be gleaned from
the envelope result.
$r->envelope->{Body}->{createResponse}->{result}->{success};
=cut

sub createHdr {
my $self = shift;
my $header = shift ->uri($SF_URI);
my (%in) = @_;

if ( !keys %in ) {
die("Expected a hash of arrays.");
}
my $client = $self->_get_client(1);
my $method =
SOAP::Data->name("create")->prefix($SF_PREFIX)->uri($SF_URI)
->attr( { 'xmlns:sfons' => $SF_SOBJECT_URI } );

my $type = $in{'type'};
delete( $in{'type'} );

my @elems;
foreach my $key ( keys %in ) {
push @elems,
SOAP::Data->prefix('sfons')->name( $key => $in{$key} )
->type( WWW::Salesforce::Constants->type( $type, $key ) );
}

my $r = $client->call(
$method => SOAP::Data->name( 'sObjects' => \SOAP::Data->value(@elems) )
->attr( { 'xsi:type' => 'sfons:' . $type } ),
$self->_get_session_header(),
$header
);
unless ($r) {
die "could not call method $method";
}
if ( $r->fault() ) {
die( $r->faultstring() );
}
return $r;
}


=head2 delete( ARRAY )
Deletes one or more individual objects from your organization's data.
Expand Down

0 comments on commit 9ea48d0

Please sign in to comment.