You need to sign in to do that
Don't have an account?
onionbagle
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:
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.
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.
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:
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:
the assignment might looks like this
$opportunity->{EVAL_License_Count__c} = 2.0;
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.