• onionbagle
  • NEWBIE
  • 0 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
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.

Hi All,

This is my first attempt at an apex trigger so please bear with me.  I am trying to write a trigger that will update other opportunity records.  The logic is as follows.

Any Opportunity is updated.
Take EVAL_serial_num__c from updated record and search all exsisting opportunity records for matching serial numbers
    If match then update the matching opportunity's field  EVAL_Stage__c = 'Returned';

I have the following code which isn't throwing any errors but at the same time it isn't updating opportunities with matching serial number fields.

Code:
trigger evaluationUpdate on Opportunity (after update) {

 for (Opportunity opp : Trigger.new)
 {
 String serialNum;
 serialNum = opp.EVAL_serial_num__c;
 
 Opportunity[] Opps = [select ID, EVAL_Stage__c from Opportunity where EVAL_serial_num__c = serialNum];
 for (Opportunity o : Opps)
 {
  if(EVAL_Stage__c != 'Returned'){
   o.update(EVAL_Stage__c = 'Returned');
   o.EVAL_Stage__c = 'Returned';
  }
 }
}
}

Any help will be appreciated.
Thanks


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.

Hi All,

This is my first attempt at an apex trigger so please bear with me.  I am trying to write a trigger that will update other opportunity records.  The logic is as follows.

Any Opportunity is updated.
Take EVAL_serial_num__c from updated record and search all exsisting opportunity records for matching serial numbers
    If match then update the matching opportunity's field  EVAL_Stage__c = 'Returned';

I have the following code which isn't throwing any errors but at the same time it isn't updating opportunities with matching serial number fields.

Code:
trigger evaluationUpdate on Opportunity (after update) {

 for (Opportunity opp : Trigger.new)
 {
 String serialNum;
 serialNum = opp.EVAL_serial_num__c;
 
 Opportunity[] Opps = [select ID, EVAL_Stage__c from Opportunity where EVAL_serial_num__c = serialNum];
 for (Opportunity o : Opps)
 {
  if(EVAL_Stage__c != 'Returned'){
   o.update(EVAL_Stage__c = 'Returned');
   o.EVAL_Stage__c = 'Returned';
  }
 }
}
}

Any help will be appreciated.
Thanks