I am using this example in order to create a new Contact on SF, my question is what happens if the Contact I am creating exists on Salesforce, how can I create that check or how can I tell Salesforce to only look at the email when I am trying to insert a new Contact because I don't want to have 2 Contacts with the same Email. (Using Email as sort of an ID for every user).
Code used in the example:
<?php
// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.ocm password
define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php');
require_once (SOAP_CLIENT_BASEDIR.'/SforceHeaderOptions.php');
require_once ('../userAuth.php');
try {
$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
$mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
$sObject = new stdclass();
$sObject->FirstName = 'Smith';
$sObject->LastName = 'John';
$sObject->Phone = '510-555-5555';
$sObject->Email = '[email protected]';
$sObject2 = new stdclass();
$sObject2->FirstName = 'Smith';
$sObject2->LastName = 'John';
$sObject2->Phone = '510-555-5555';
$sObject2->Email = '[email protected]';
echo "**** Creating the following:\r\n";
$createResponse = $mySforceConnection->create(array($sObject, $sObject2), 'Contact');
} catch (Exception $e) {
echo $mySforceConnection->getLastRequest();
echo $e->faultstring;
}
?>
Basically, I want this query to work and SF to create two different contacts, use ONLY the email as a check for duplicates.
Right now I am getting this error:
Standard_Contact_Match_Rule_v1_1
Contact_with_same_email_already_exists_in_SF
EDIT: I have tried to play with the library source and still can't get AllowSave to work. Here are the code changes:
SforceBaseClient.php Line 51:
class SforceBaseClient {
protected $duplicateRuleHeader; //Added
SforceBaseClient.php Line 226:
if ($call == "create" ||
$call == "resetPassword" ||
$call == "update" ||
$call == "upsert"
) {
$header = $this->duplicateRuleHeader;
if ($header != NULL) {
array_push($header_array, $header);
}
}
SforceBaseClient.php Line 347:
public function setDuplicateRuleHeader($header) {
if($header != NULL) {
$this->duplicateRuleHeader = new SoapHeader($this->namespace, 'DuplicateRuleHeader', array (
'allowSave' => $header->allowSave,
'includeRecordDetails' => $header->includeRecordDetails,
'runAsCurrentUser' => $header->runAsCurrentUser
));
}
else {
$this->duplicateRuleHeader = NULL;
}
}
SforceHeaderOption.php Line 74:
/**
* To be used with Create and Update operations.
* Only one attribute can be set at a time.
*
* @package SalesforceSoapClient
*/
class DuplicateRuleHeader {
// boolean
public $allowSave, $includeRecordDetails, $runAsCurrentUser;
/**
* Constructor. Only one param can be set.
*
* @param boolean $allowSave allowSave flag
* @param boolean $includeRecordDetails includeRecordDetails flag
* @param boolean $runAsCurrentUser runAsCurrentUser flag
*/
public function __construct($allowSave = NULL, $includeRecordDetails = NULL, $runAsCurrentUser = NULL) {
if($allowSave != NULL) {
$this->allowSave = $allowSave;
}
if($includeRecordDetails != NULL) {
$this->includeRecordDetails = $includeRecordDetails;
}
if($runAsCurrentUser != NULL) {
$this->runAsCurrentUser = $runAsCurrentUser;
}
}
}
I'm calling:
$header = new DuplicateRuleHeader(true);
$mySforceConnection->set setDuplicateRuleHeader($header);
I still get the Duplicate contact error, any ideas? what am I missing?
Rule Name - Contact already exists in SF, Record-Level Security Enforce sharing rules, Action On Create - Block, Conditions Contact: Contact Record Type EQUALS Donor
Account Name, Email, First Name, Last Name, Mailing City, Mailing Street, Mailing Zip/Postal Code, Phone, Title
so if another person from another country that has the same first name and last name donates I will get this silly duplicate error, that's why I want to use allowSave to create a new contact. I want to use the Email field as an ID.