Over at the Salesforce.com developer forums Paul asked for some help on his custom object to create records in a custom object he had created for his Org, called PFC_API and could not get the script to work.
Here is an working script with some of the fields from his script that I have tested against my developers org. I created the same fields in an object that I created called PFC_API:
This works and should work for anyone that needs to modify it for their custom objectPHP Code:<?php
ini_set("soap.wsdl_cache_enabled", "0");
require_once ('./includes/soapclient/SforcePartnerClient.php');
require_once ('./includes/soapclient/SforceHeaderOptions.php');
$campaign_read = "My Campaign";
$document_read = "My Document";
$emailid = "contact@email.com";
$sfid = "00550000000wI2LAAU";
$ownerid = $sfid;
$name = "Samsung";
$mystuff = array('Name' => $name,
'OwnerId' => $ownerid,
'PFC_Campaign__c' => $campaign_read,
'PFC_Document_Name__c' => $document_read,
'PFC_Contact_Email__c' => $emailid,
'Contact__c' => $sfid,
'PFC_Action__c' => 'Read', );
//clean contacts to allow changing of characters to XML
$mystuff = array_map('htmlspecialchars', $mystuff);
//try to add contact from form
try
{
//salesforce login and wsdl
$wsdl = './includes/soapclient/partner.wsdl.xml';
$userName = "changeme";
$password = "changeme";
//connect to salesforce
$client = new SforcePartnerClient();
$client->createConnection($wsdl);
$loginResult = $client->login($userName, $password);
$sObject = new sObject();
$sObject->type = 'PFC_API__c';
$sObject->fields = $mystuff;
//this part adds the contact to salesforce
$result = $client->create(array($sObject));
if ($result->success)
{
echo "New Record has been added to your custom Object with and id of " . $result->id . "<br />";
echo "**************** ALL DONE ****************<br />";
exit;
}
else
{
$errMessage = $result->errors->message;
echo $errMessage;
}
}
catch (exception $e)
{
// This is reached if there is a major problem in the data or with
// the salesforce.com connection. Normal data errors are caught by
// salesforce.com
echo '<pre>' . print_r($e, true) . '</pre>';
return false;
exit;
}
?>
~Mike
@Mike
I used your code to try to create a record. I slightly modified the array and the object type.
I get this error:PHP Code:<?php
ini_set("soap.wsdl_cache_enabled", "0");
require_once ('./includes/soapclient/SforcePartnerClient.php');
require_once ('./includes/soapclient/SforceHeaderOptions.php');
$mystuff = array('Username' => 'user@email.com', // change this to a valid email
'LastName' => 'Wiley',
'FirstName' => 'Mike',
'Email' => 'user@email.com', // change this to a valid email
'Alias' => 'MWile',
'IsActive' => 'true',
'TimeZoneSidKey' => 'America/New_York',
'LocaleSidKey' => 'en_US',
'EmailEncodingKey' => 'ISO-8859-1',
'ProfileId' => '00550000000wI2LAAU',
'LanguageLocaleKey'=> 'en_US');
//clean User to allow changing of characters to XML
$mystuff = array_map('htmlspecialchars', $mystuff);
//try to add User from from array
try
{
//salesforce login and wsdl
$wsdl = './includes/soapclient/partner.wsdl.xml';
$userName = "email@gmail.com";
$password = "somepassword";
//connect to salesforce
$client = new SforcePartnerClient();
$client->createConnection($wsdl);
$loginResult = $client->login($userName, $password);
$sObject = new sObject();
$sObject->type = 'User';
$sObject->fields = $mystuff;
//this part adds the contact to salesforce
$result = $client->create(array($sObject));
if ($result->success)
{
echo "New User has been added to your instance of Salesforce with an Id of " . $result->id . "<br />";
echo "**************** ALL DONE ****************<br />";
exit;
}
else
{
//print "Unsucessful Create<br>";
$errMessage = $result->errors->message;
echo $errMessage;
}
}
catch (exception $e)
{
// This is reached if there is a major problem in the data or with
// the salesforce.com connection. Normal data errors are caught by
// salesforce.com
echo '<pre>' . print_r($e, true) . '</pre>';
return false;
exit;
}
?>
invalid cross reference id
have any ideas how to fix this error?
Ncee
Can you post just the lines that you changed? and did you use this example or the one from this URL > http://www.mikesimonds.com/create-us...e-php-t54.html
~Mike
PS > maybe you could email me the script if you do not want to post it here
Mike,
I used the code at http://www.mikesimonds.com/create-us...e-php-t54.html and modified the username and password to my cridentials.
Do you think it might have something to do with the profileID in the array?PHP Code:
$userName = "email@gmail.com";
$password = "somepassword";
~NCEE
yes that is what the error is telling me!
I got that profile ID from my dev instance, try and switch yours and rerun the script
Bookmarks