About Me
Survival Paladin
Paranoid, Delusional, Nerdy, Egotistical and i like cats.
View my complete profile
Blog Archive
September
(1)
June
(3)
Monday, June 27, 2011
Salesforce & Perl & Catalyst - Building a Listener for Outbound Messages
package YOURPACKAGENAME::SFDC; use strict; use SOAP::Lite; use Data::Dumper; use Moose; use namespace::autoclean; use XML::Simple; use WWW::Salesforce; BEGIN {extends 'Catalyst::Controller'; } sub index : Private { my ($self, $c, $args) = @_; # The xml comes in as a file format my $FH = $c->request->body; # If there is a file, slurp in the data if($FH){ my $raw_xml = do { local $/; <$FH> }; my $xml_simple = XML::Simple->new( ); my $xml_hash = $xml_simple->XMLin($raw_xml, ForceArray => 1); my $object = $xml_hash->{'soapenv:Body'}->[0]->{'notifications'}->[0]->{'Notification'}->[0]->{'sObject'}->[0]; my $type = $object->{'xsi:type'}; # App Type is Job Application if($type =~ m/Job_Application/){ warn("Type is: Job Application"); my $application_hash = { 'last_modified_date' => $object->{'sf:LastModifiedDate'}->[0], 'name' => $object->{'sf:Name'}->[0], 'created_by' => $object->{'sf:CreatedById'}->[0], 'is_deleted' => $object->{'sf:IsDeleted'}->[0], 'candidate_id' => $object->{'sf:Candidate__c'}->[0], 'id' => $object->{'sf:Id'}->[0], 'cover_letter' => $object->{'sf:Cover_Letter__c'}->[0], 'status' => $object->{'sf:Status__c'}->[0], 'created_date' => $object->{'sf:CreatedDate'}->[0], 'last_modified_by' => $object->{'sf:LastModifiedById'}->[0], 'owner_id' => $object->{'sf:OwnerId'}->[0] }; # You now have the data, do what you want with it warn("==============================================="); warn(Dumper($application_hash)); warn("==============================================="); } } # Dump out the acknowledge. my $response = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <notificationsResponse xmlns="http://soap.sforce.com/2005/09/outbound"> <Ack>true</Ack> </notificationsResponse> </soapenv:Body> </soapenv:Envelope>'; # We now have it so you don't need to set the view type to none. #$c->stash->{'view_type'} = 'None'; $c->response->body($response); return(); } __PACKAGE__->meta->make_immutable; 1;
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment