function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
onionbagleonionbagle 

Need help using perl update()

Hi,

I am haveing some trouble with the WWW::Salesforce module for perl.  Specifically the update() function.  Cpan says all the function takes is a hash. I have tried passing the function many variations but it always responds with expecting key 'id' or 'type'.  I have gotten past those errors by placing them as arguments but then I get the error Unexpected element {}item during simple type deserialization.  Below is my current code.  Can someone please chime in with an example for the update function.  Thanks.

Code:
$sf = WWW::Salesforce->login(username => 'xxxxxxxxx@xxxxx.com', password => 'XXXXX') or die $!;
$query = "select Id, OPP_ID__c, EVAL_Expiration__c, EVAL_Licence_Count__c from Opportunity";
$result = $sf->query('query' => $query);
 foreach my $elem($result->valueof('//queryResponse/result/records')){
        print "$elem->{Id}[0], $elem->{OPP_ID__c}, $elem->{EVAL_Expiration__c}, $elem->{EVAL_Licence_Count__c} \n";
        $opID{$elem->{Id}[0]} = $elem->{OPP_ID__c};
        $evalExp{$elem->{Id}[0]} = $elem->{EVAL_Expiration__c};
        $licCount{$elem->{Id}[0]} = $elem->{EVAL_License_Count__c};
}

#loop that builds opportunity hash and updates
while(($key, $value) = each(%opID)){
        print "start\n";
        #$opportunity{'type'} = 'ens:sObject';
        $opportunity{"id"} = [$key, 'sforce:ID'];
        if(exists $licenseCount{$value}){
                #$opportunity{"EVAL_Licence_Count__c"} = $licenseCount{$value};
                $opportunity{"EVAL_License_Count__c"} = [$licenseCount{$value},'xsd:double'];
        }

        $result= $sf->update(type=>'Opportunity', %opportunity);
        if($result->result->{"success"} eq "false") {
                print $result->result->{errors}->{message} . "\n";
        }
        print "end\n";
}

 With the code shown above the while loop errors out on its first loop with the following error
"Unexpected element {}item during simple type deserialization at line 71"   which is the call for the update function.

onionbagleonionbagle
Ok it looks like I solved my problem or at least got the update function to work.  I haven't verifed if what I am updating is correct yet.

The problem was I was setting the hash key and value for type and id too soon.  See the code below for the order that update() works with.

Code:
%opportunity = ()
$opportunity{"id"} = $key; 
$opportunity{"EVAL_License_Count__c"} = $licenseCount{$key};
$opportunity{"type"} = "Opportunity";  #This has to be set right before calling update() because the way update looks for type in the hash.

$result = $sf->update(%opportunity);

 

onionbagleonionbagle
Well now I have another problem with update()

It seems when the update function tries to update one of the custom fields it can't because of its type.  The error I am getting is "EVAL Licence Count: value not of required type: 2".  I know update is suppose to guess at what type it is but it must be guessing wrong.  I know the type for my value is xds:double.  I just don't know how to tell update what its type is.


I have tried the following bits but nothing seems to work.

Code:
$Salesforce::Constants::TYPES{Opportunity}->{EVAL_License_Count__c}='xds:double';
$Salesforce::Constants::TYPES{'Opportunity'}->{'EVAL License Count'}='xds:double';

or 

$opportunity{"EVAL_License_Count__c"} = [$licenseCount{$value}, 'xds:double'];

 

Ron HessRon Hess
this should be correct
$Salesforce::Constants::TYPES{Opportunity}->{EVAL_License_Count__c}='xds:double';




the assignment might looks like this

 $opportunity->{EVAL_License_Count__c} = 2.0;

onionbagleonionbagle
Ron,

Thanks for your response.  I actually ended up getting this to work earlier.  I fixed a pervious problem and tried all my options for TYPE declaration.  Thanks again.