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
fhuifhui 

Problem to update custom Date field with Perl.

I have a problem to update a custom field in Date type with Perl. When I run the query to select some custom fields, all the fields of the return hash are strings even some of the fields are Date type. If I try to update the field which suppose to be Date type, it return the error message "INVALID_TYPE_ON_FIELD_IN_RECORD". Any suggestion??
 
Below is my code :
sub test
{
my $result, $nw_designerId;
my $q2 = "Select Id, FA_Reason__c, FA_Status__c, FA_Design_Owner__c, FA_Completed_Date__c from FA__c where Name = 'FA070427-000181'";
$result = $port->query('query' => $q2, 'limit' => '200');
print "We got " . $result->valueof('//queryResponse/result/size') . " back.\n";
foreach my $elem ($result->valueof('//queryResponse/result/records')) {
 print "$elem->{Id}, $elem->{FA_Reason__c}, $elem->{FA_Status__c}, $elem->{FA_Design_Owner__c}, $elem->{FA_Completed_Date__c} \n";
 $elem->{FA_Status__c} = "Open";
 $elem->{FA_Completed_Date__c} = '2006-12-19T19:51:12.174Z';
 my $foo = $port->update(%{$elem});
 print "$foo\n"; # should print "1" if $port->update() succeeded.
 }
}
 
Here is the error message :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"
>
 <SOAP-ENV:Header
 >
   <SessionHeader
   >
     <sessionId xsi:type="xsd:string"
     >qDb2EUAjvgXw.LCb0f0L2NKx.BWxDv7gz3bcv_ZG7kgNuN6hbwE5EFaQtw_oR3obk4geuh36LW6VeH7JQ42op6QN9vOJezg802hoRYiHuRHjAF3vhkCDbMBZDURxjIkv4b4A8wCU</sessionId></SessionHeader></SOAP-ENV:Header>
 <SOAP-ENV:Body
 >
   <sforce:update xmlns:sfons="urn:sobject.partner.soap.sforce.com" xmlns:sforce="urn:partner.soap.sforce.com"
   >
     <sObjects xsi:type="sforce:FA__c"
     >
       <sforce:Id xsi:null="1" xsi:type="sforce:ID"/>
       <sforce:FA_Reason__c xsi:type="xsd:string"
       >Initial FA</sforce:FA_Reason__c>
       <sforce:FA_Status__c xsi:type="xsd:string"
       >Open</sforce:FA_Status__c>
       <sforce:Id xsi:type="xsd:string"
       >a0530000002fL8ZAAU</sforce:Id>
       <sforce:FA_Design_Owner__c xsi:type="xsd:string"
       >00530000000swzaAAA</sforce:FA_Design_Owner__c>
       <sforce:FA_Completed_Date__c xsi:type="xsd:string"
       >2006-12-19T19:51:12.174Z</sforce:FA_Completed_Date__c></sObjects></sforce:update></SOAP-ENV:Body></SOAP-ENV:Envelope>
SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK
Cache-Control: private
Date: Tue, 21 Aug 2007 21:52:00 GMT
Server:
Content-Type: text/xml; charset=utf-8
Client-Date: Tue, 21 Aug 2007 21:52:01 GMT
Client-Peer: 204.14.234.40:443
Client-Response-Num: 1
Client-SSL-Cert-Issuer: /O=VeriSign Trust Network/OU=VeriSign, Inc./OU=VeriSign International Server CA - Class 3/OU=www.verisign.com/CPS Incorp.by Ref. LIABILITY LTD.(c)97 VeriSign
Client-SSL-Cert-Subject: /C=US/ST=California/L=San Francisco/O=Salesforce.com, Inc./OU=Applications/OU=Terms of use at www.verisign.com/rpa (c)00/CN=na1-api.salesforce.com
Client-SSL-Cipher: RC4-MD5
Client-SSL-Warning: Peer certificate not verified
Client-Transfer-Encoding: chunked
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
 <soapenv:Body>
 <updateResponse xmlns="urn:partner.soap.sforce.com">
  <result>
   <errors>
    <fields>FA_Completed_Date__c</fields>
    <message>FA Completed Date: value not of required type: 2006-12-19T19:51:12.174Z</message>
    <statusCode>INVALID_TYPE_ON_FIELD_IN_RECORD</statusCode>
   </errors>
   <id xsi:null="true"/>
   <success>false</success>
  </result>
 </updateResponse>
 </soapenv:Body>
</soapenv:Envelope>
SuperfellSuperfell
The problem is that although its a date, the request says its a string

>2006-12-19T19:51:12.174Z

You need to tell the perl stuff that its really a date, i know that's its possible, but i don't know exactly how its done.
fhuifhui
Yes, I thought about to change the data type of the return hash. However, I can't find any sample code or API to change data type in Perl. Anybody knows?
 
thanks,
-Florence
Ron HessRon Hess
when using the SOAP::Lite package and the Salesforce module, you can cast the types you need.

soap::lite default is guessed by the content,
which works for strings and sometimes numbers, but not always boolean or dates

add some code like this:

# type casting for non string type fields
$Salesforce::Constants::TYPES{FA__c}->{FA_Completed_Date__c} = 'xsd:date';


put this way early in your code, must be before your query is seralized,
it should work ( add xsd:date to the soap )

good luck!


fhuifhui

Ron,

   It works beautiful !!

thanks for your help,

-Florence

gengelgengel
Any way to do something similar in PHP?