I am using salesforce toolkit PHP to create an Opportunity. Everything works great but I random duplicate record creation which is driving me crazy. Does anyone know how to fix this problem? I can't see why this is happening.

Here is my code:

require_once 'soapclient/SforcePartnerClient.php';

$mySforceConnection = new SforcePartnerClient();


if (isset($_SESSION['partnerSessionId'])) {
    $location = $_SESSION['partnerLocation'];
    $sessionId = $_SESSION['partnerSessionId'];


} else {
    $mySforceConnection->login(USERNAME, PASSWORD);

    $_SESSION['partnerLocation'] = $mySforceConnection->getLocation();
    $_SESSION['partnerSessionId'] = $mySforceConnection->getSessionId();

$records = array();
$records[0] = new SObject();
$records[0]->fields = array(

    'RecordTypeId' => '0124J0000000VDN',
    'Name' => 'New Opportunity',
    'AccountId' => '0014J00000OnWvhQAF',
    'CloseDate' => '2022-06-28',
    'StageName' => 'Ordered',
    'Amount' => '1.00',
    'OwnerID' => '0054J000005JDwh',


$records[0]->type = 'Opportunity';

$response = $mySforceConnection->create($records);

  • 1
    is your code being execute via an (HTML) button? It sounds like a button was pressed twice?. Jun 7 '21 at 12:34
  • Hi, no I just execute the code by running the script no buttons. I have read other people having the same problem, thank you for the intrest.
    – Simon Webb
    Jun 7 '21 at 12:50
  • It looks like this has been known behavior observed with Salesforce toolkit PHP, You can utilize duplicate rules as a workaround until the reason is not clear. Jun 7 '21 at 14:53
  • Thanks Shivankur, I'll take a look
    – Simon Webb
    Jun 7 '21 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.