Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add createHdr() method which allows a header to be passed to the Salesforce create API. #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ 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.

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

## delete( ARRAY )

Deletes one or more individual objects from your organization's data.
Expand Down
51 changes: 51 additions & 0 deletions lib/WWW/Salesforce.pm
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,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