0

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();

$mySforceConnection->createConnection("soapclient/partner.wsdl.xml");

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

    $mySforceConnection->setEndpoint($location);
    $mySforceConnection->setSessionHeader($sessionId);

} 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);



4
  • 1
    is your code being execute via an (HTML) button? It sounds like a button was pressed twice?. – Cuban coffee Jun 7 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 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. – Shivankur Naikwade Jun 7 at 14:53
  • Thanks Shivankur, I'll take a look – Simon Webb Jun 7 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.