You need to sign in to do that
Don't have an account?
sgenin
I can't create objects using the API
Hello,
I try to insert objects using the PHP API.
All the SELECT commands work, the CREATE commands return no error, but nothing is created.
Here is my code :
$client = new SalesforceClient($result->sessionId);
$client->_endpoint = $result->serverUrl;
$client->setOpt("timeout", 60);
$query_str = "select Id,description from lead where email='$email' and isConverted=False";
$result = $client->query($query_str);
if (PEAR::isError($result))
{
print "
$ret=0;
}
else
{
// No lead in the database
if (count($result->records) == 0)
{
$FIELDS=array(
'type' => 'lead',
'FirstName' => utf8_encode($firstname),
'LastName' => utf8_encode($lastname),
'Title' => utf8_encode($title),
'Company' => utf8_encode(strtoupper($company)),
'Website' => utf8_encode($url),
'Email' => utf8_encode($email),
'Phone' => utf8_encode($phone),
'Street' => utf8_encode($street),
'PostalCode' => utf8_encode($zip),
'City' => utf8_encode($city),
'Country' => utf8_encode($country),
'LeadSource' => utf8_encode($know_us),
'Recevoir_les_Infos_modifi_le__c' => $info_date,
'Recevoir_les_Infos_par_email__c' => utf8_encode($info_str),
'Recevoir_la_Newsletter__c' => utf8_encode($news_str),
'Recevoir_la_Newsletter_modifie_le__c' => $nl_date,
'Origine_du_contact__c' => utf8_encode($source));
$result=$client->create($FIELDS);
if (PEAR::isError($result))
{
print ("
$ret=0;
}
}
}
At the end, I have no error, but nothing is inserted...
Can someone help me please?
Thanks
Stéphane
I try to insert objects using the PHP API.
All the SELECT commands work, the CREATE commands return no error, but nothing is created.
Here is my code :
$client = new SalesforceClient($result->sessionId);
$client->_endpoint = $result->serverUrl;
$client->setOpt("timeout", 60);
$query_str = "select Id,description from lead where email='$email' and isConverted=False";
$result = $client->query($query_str);
if (PEAR::isError($result))
{
print "
".$result->getMessage()."
";
print "$query_str
$ret=0;
}
else
{
// No lead in the database
if (count($result->records) == 0)
{
$FIELDS=array(
'type' => 'lead',
'FirstName' => utf8_encode($firstname),
'LastName' => utf8_encode($lastname),
'Title' => utf8_encode($title),
'Company' => utf8_encode(strtoupper($company)),
'Website' => utf8_encode($url),
'Email' => utf8_encode($email),
'Phone' => utf8_encode($phone),
'Street' => utf8_encode($street),
'PostalCode' => utf8_encode($zip),
'City' => utf8_encode($city),
'Country' => utf8_encode($country),
'LeadSource' => utf8_encode($know_us),
'Recevoir_les_Infos_modifi_le__c' => $info_date,
'Recevoir_les_Infos_par_email__c' => utf8_encode($info_str),
'Recevoir_la_Newsletter__c' => utf8_encode($news_str),
'Recevoir_la_Newsletter_modifie_le__c' => $nl_date,
'Origine_du_contact__c' => utf8_encode($source));
$result=$client->create($FIELDS);
if (PEAR::isError($result))
{
print ("
".$result->getMessage()."
");
print_r ("$FIELDS
$ret=0;
}
}
}
At the end, I have no error, but nothing is inserted...
Can someone help me please?
Thanks
Stéphane
Stéphane
2005-10-15T00:00:00.000+00:00
in PHP,
$startDate = date('Y-m-d\TH:i:s.000+00:00', mktime(0, 0, 0, 10, 15, 2005));
I now check the value : $result->success, and the value is false.
However, I'm not an expert in PHP, and I can't find the way to retrieve the error message itself : I tried $result->errors->message, and $result->errors->message[0] and it doesn't work.
Thanks
Stéphane
The strange thing is that I have the same code source working on another server...
Stéphane
I managed to get the error code and message :
message=Recevoir les Infos modifié le: valeur de type non valide : 2005-10-15T00:00:00.000+00:00
statusCode=INVALID_TYPE_ON_FIELD_IN_RECORD
I also tried with 2005-10-15, and I get the same error.
In the WDSL, the field description is :
Thanks again for your help
Stéphane
<someDate xsi:type='xsi:String'>2005-10-10T11:11:11Z<someDate>
Even though you have the correctly formatted dateTime, this is claiming its a string not a dateTime, and so the server errors because its requiring a date (or dateTime).
You need to make sure the client either doesn't send the xsi:type attribute, or sends the correct value.
$SOAP_RAW_CONVERT = true;
somewhere in your code: it just needs to be in the global name space.
This can cause other problems as the serializer will now attempt to convert every string to another data type: integer, binary (base64) or date_time. You can get around this by appending a single space to the end of string values that might contain [0-9]* or [a-zA-Z0-9]*.
There may be a better solution (other than switching to the native lib in PHP5) but this will work. The conversion code is in SOAP/BASE.php if you're interested. Using this method, gmdate("Y-m-d\TH:i:s",time()) will give you a date that the API will take.
Park
At least some versions of the library us this flag in the SOAP/Base module to decide whether to attempt to parse doubles, base64 and date values, or leave them as strings.