Subject: | Suggested changes to the API |
Date: | Thu, 14 May 2009 16:20:50 -0600 |
To: | <bug-WWW-Salesforce [...] rt.cpan.org> |
From: | "Reggie Sniff" <rsniff [...] amllc.com> |
I am using the API and it works wonderfully with a few exceptions.
Unfortunately, I have had to pretty much copy your code and make changes to
support my needs.
The problems I have, and I assume others might have is that from within most
parts of the code, whenever you get an error, you use "carp $err" and then
you return 0 or you attempt to use 'carp($res->faultstring())'. Both of
these are problematic for different reasons. In the first, I only have
access to the error if I have access to STDERR. It would be much better if
it was returned or stored in some global hash. The second also causes
problems if the $res object fails to get instantiated. When this happens,
if you try to call $res->faultstring() on a non-existent reference, the
code dies. When $res fails to get a reference it actually returns a scalar
(error message) rather then the ref object you are expecting.
To use an example, what I have done is this:
Instead of this code:
------------
if ( !defined $table_name || !length $table_name ) {
carp( 'Param1 of get_field_list() should be a string' );
return 0;
}
my $res = $self->describeSObject( 'type' => $table_name );
if ( $res->fault() ) {
carp( $res->faultstring() );
return 0;
}
-----------------
I use this -t allows me to have access to the error (and email it back to
muyself) without having to look through a log file:
------------
if ( !defined $table_name || !length $table_name ) {
# I am returning the error so that I can handle it. I just need
to check the ref() of the returned value first
return ( 'Param1 of get_field_list() should be a string' );
}
my $res = $sforce->describeSObject( 'type' => $table_name );
# If the above fails the $res object is a scalar error message
unless (ref($res)) {
return $res;
}
# This should never be reached if $res is not a proper reference
if ( $res->fault() ) {
return ( $res->faultstring() );
}
------------
Regards,
Reggie Sniff