• huffenstein
  • NEWBIE
  • 0 Points
  • Member since 2006

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I am not sure if any of you have experienced the same problems that I did, but just in case any of you have.

I could not find any defininative anwsers on this in any of the forums, so I am posting it here for everyone elses benefit.

When using the salesforce.cgi example script that comes with the Salesforce-0.54.tar.gz package off of sforce.sourceforge.net I was getting the following error:

UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService

I looked for this error on the forums and found a couple of places that talked about this problem with PHP and with the Excel Connector, but none dealing with the perl Salesforce module.

It would appear that the API requirements have changed since the module was written, as now you have to save the 'serverUrl' and 'address' along with the sessionId in order to be able to use that sessionId in a subsequent API call.

I modified the salesforce.cgi script to create another cookie to store the serverUrl value for later use.

I modified the  'submit eq Login' 'if' statement as follows:

} elsif (param('submit') eq 'Login') {
    my $result = $port->login('username' => param('username'),
                              'password' => param('password'));
    my $cookie = cookie( -NAME  => 'sf_session',
                         -VALUE => $port->{'sessionId'});
    my $cookie1 = cookie( -NAME  => 'sf_serverurl',
                          -VALUE => $port->{'serverUrl'});
    print header( -COOKIE => [$cookie,$cookie1],
        -LOCATION => "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?action=list");
    exit;
}


this allows the storing of the serverUrl in a cookie for later use.

I added:

my $SERVURL  = cookie('sf_serverurl');

at the top of the script to grab the data out of the cookie.

then I added:

$port->{'address'} = $SERVURL;

right after the setting of $port->{'sessionId'}.

Hopefully this will help someone one else who is struggling trying to get the saleforce.cgi example script ( and thereby other code using Salesforce.pm API sessions ) working.

While I was at it I also threw in a proper <form> tag and submit button so that you could actually use the dropdown for 'Results per Page'.

I just want to say thanks to the author of the Salesforce.pm module.  It will save me a great amount of time in writing code not having to deal with the foibles of SOAP::Lite and the salesforce wsdl.

A full 'diff -Naur' ( which will allow you to patch the file ) is included below.


--- salesforce.cgi      Tue Dec 16 11:47:40 2003
+++ salesforceM.cgi     Thu Jun  8 02:39:06 2006
@@ -13,6 +13,7 @@
 my $LIMIT    = param('per') || 10;
 my $ACTION   = param('action') || 'list';
 my $SESSION  = cookie('sf_session');
+my $SERVURL  = cookie('sf_serverurl');
 
 my $service = new Salesforce::SforceService;
 my $port = $service->get_port_binding('Soap');
@@ -27,20 +28,25 @@
     my $cookie = cookie( -NAME => 'sf_columns',
                         -VALUE => join(',',param('col')));
     print header( -COOKIE => $cookie,
-                 -LOCATION => "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?action=list");
+                 -LOCATION => "https://clink.colltech.com$ENV{SCRIPT_NAME}?action=list");
     exit;
 } elsif (param('submit') eq 'Login') {
     my $result = $port->login('username' => param('username'),
                              'password' => param('password'));
     my $cookie = cookie( -NAME => 'sf_session',
                         -VALUE => $port->{'sessionId'});
-    print header( -COOKIE => $cookie,
-       -LOCATION => "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?action=list");
+    my $cookie1 = cookie( -NAME => 'sf_serverurl',
+                        -VALUE => $port->{'serverUrl'});
+    print header( -COOKIE => [$cookie,$cookie1],
+       -LOCATION => "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?action=list");
     exit;
 }
 my $COLUMNS  = cookie('sf_columns') || 'Id,FirstName,LastName';
 
 $port->{'sessionId'} = $SESSION;
+#$port->{'serverUrl'} = $SERVURL;
+$port->{'address'} = $SERVURL;
+
 
 print header( -TYPE => 'text/html' );
 print_header();
@@ -82,6 +88,7 @@
 sub list {
     print <<END_HTML;
 <p>
+<form>
 Results per page:
 <select name="per">
   <option>10</option>
@@ -110,12 +117,12 @@
        print "<tr".($i % 2 == 0 ? " bgcolor=\"#EEEEEE\"" : "").">";
        printf "<td>%d.</td>",++$i;
        foreach my $col (split(',',$COLUMNS)) {
-           printf "<td>%s</td>",$elem->{$col};
+           printf "<td>%s</td>",$elem->{$col}[0] ? $elem->{$col}[0] : $elem->{$col};
        }
        print "</tr>\n";
     }
 }
-print '</table>'."\n";
+print '</table><input type=submit name="submit"></form>'."\n";
 
 print <<END_HTML;
 <br />




I am not sure if any of you have experienced the same problems that I did, but just in case any of you have.

I could not find any defininative anwsers on this in any of the forums, so I am posting it here for everyone elses benefit.

When using the salesforce.cgi example script that comes with the Salesforce-0.54.tar.gz package off of sforce.sourceforge.net I was getting the following error:

UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService

I looked for this error on the forums and found a couple of places that talked about this problem with PHP and with the Excel Connector, but none dealing with the perl Salesforce module.

It would appear that the API requirements have changed since the module was written, as now you have to save the 'serverUrl' and 'address' along with the sessionId in order to be able to use that sessionId in a subsequent API call.

I modified the salesforce.cgi script to create another cookie to store the serverUrl value for later use.

I modified the  'submit eq Login' 'if' statement as follows:

} elsif (param('submit') eq 'Login') {
    my $result = $port->login('username' => param('username'),
                              'password' => param('password'));
    my $cookie = cookie( -NAME  => 'sf_session',
                         -VALUE => $port->{'sessionId'});
    my $cookie1 = cookie( -NAME  => 'sf_serverurl',
                          -VALUE => $port->{'serverUrl'});
    print header( -COOKIE => [$cookie,$cookie1],
        -LOCATION => "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?action=list");
    exit;
}


this allows the storing of the serverUrl in a cookie for later use.

I added:

my $SERVURL  = cookie('sf_serverurl');

at the top of the script to grab the data out of the cookie.

then I added:

$port->{'address'} = $SERVURL;

right after the setting of $port->{'sessionId'}.

Hopefully this will help someone one else who is struggling trying to get the saleforce.cgi example script ( and thereby other code using Salesforce.pm API sessions ) working.

While I was at it I also threw in a proper <form> tag and submit button so that you could actually use the dropdown for 'Results per Page'.

I just want to say thanks to the author of the Salesforce.pm module.  It will save me a great amount of time in writing code not having to deal with the foibles of SOAP::Lite and the salesforce wsdl.

A full 'diff -Naur' ( which will allow you to patch the file ) is included below.


--- salesforce.cgi      Tue Dec 16 11:47:40 2003
+++ salesforceM.cgi     Thu Jun  8 02:39:06 2006
@@ -13,6 +13,7 @@
 my $LIMIT    = param('per') || 10;
 my $ACTION   = param('action') || 'list';
 my $SESSION  = cookie('sf_session');
+my $SERVURL  = cookie('sf_serverurl');
 
 my $service = new Salesforce::SforceService;
 my $port = $service->get_port_binding('Soap');
@@ -27,20 +28,25 @@
     my $cookie = cookie( -NAME => 'sf_columns',
                         -VALUE => join(',',param('col')));
     print header( -COOKIE => $cookie,
-                 -LOCATION => "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?action=list");
+                 -LOCATION => "https://clink.colltech.com$ENV{SCRIPT_NAME}?action=list");
     exit;
 } elsif (param('submit') eq 'Login') {
     my $result = $port->login('username' => param('username'),
                              'password' => param('password'));
     my $cookie = cookie( -NAME => 'sf_session',
                         -VALUE => $port->{'sessionId'});
-    print header( -COOKIE => $cookie,
-       -LOCATION => "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?action=list");
+    my $cookie1 = cookie( -NAME => 'sf_serverurl',
+                        -VALUE => $port->{'serverUrl'});
+    print header( -COOKIE => [$cookie,$cookie1],
+       -LOCATION => "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?action=list");
     exit;
 }
 my $COLUMNS  = cookie('sf_columns') || 'Id,FirstName,LastName';
 
 $port->{'sessionId'} = $SESSION;
+#$port->{'serverUrl'} = $SERVURL;
+$port->{'address'} = $SERVURL;
+
 
 print header( -TYPE => 'text/html' );
 print_header();
@@ -82,6 +88,7 @@
 sub list {
     print <<END_HTML;
 <p>
+<form>
 Results per page:
 <select name="per">
   <option>10</option>
@@ -110,12 +117,12 @@
        print "<tr".($i % 2 == 0 ? " bgcolor=\"#EEEEEE\"" : "").">";
        printf "<td>%d.</td>",++$i;
        foreach my $col (split(',',$COLUMNS)) {
-           printf "<td>%s</td>",$elem->{$col};
+           printf "<td>%s</td>",$elem->{$col}[0] ? $elem->{$col}[0] : $elem->{$col};
        }
        print "</tr>\n";
     }
 }
-print '</table>'."\n";
+print '</table><input type=submit name="submit"></form>'."\n";
 
 print <<END_HTML;
 <br />