0

I am using PHP Toolkit 20 to integrate a donation form to Salesforce. Here is the code i'm using:

/*
* This function creates a Donation on Salesforce. Fires when Contact already exists on Salesforce.
* It affiliates the donation to the Account of the Contact found.
*/

// Select contact
$query = 'SELECT Id FROM Account WHERE npe01__One2OneContact__c=\'' . $ContantFound . '\'';
$temp = (Array)$mySforceConnection->query($query);
$AccoundId = $temp['records'][0]->Id;

// Creating Donation
$Donation = new stdClass();
$Donation->Name                     = prepare_input($_POST['firstname']) . ' ' . prepare_input($_POST['lastname']) . ' - Donation ' . date('Y-m-d');
$Donation->AccountId                = $AccoundId;
$Donation->StageName                = 'Donated';
$Donation->CloseDate                = date('Y-m-d h:m:iZ');
$Donation->Amount                   = prepare_input($_POST['amount']);
$Donation->CurrencyIsoCode          = $currency;
$Donation->npsp__Primary_Contact__c = $ContantFound; // Contact ID
$result = $mySforceConnection->create(array($Donation), 'Opportunity');
if(!$result) {
    throw new Exception('Error adding a Donation: ' . $result);
}

Basically I am querying the database beforehand, getting data from the Posted form and checking it against the database to see if I have a Contact with that First Name, Last Name and Email and if I found one the above code will run.

The issue is that I particularly set $Donation->StageName = 'Donated'; but it seems that it's not working well because one time I try to test donate, the stage on Salesforce is set to Donated and another time it says Partially Paid, it doesn't seem to have any pattern to it.

Do you have any idea why this is happening?

  • 1
    did you check workflows, processes and triggers related to Opportunity sobject, if you are not getting any exceptions, as a response on your request ? – Oleksandr Berehovskyi Jul 5 '17 at 9:09
  • I am not getting ANY exceptions on my response, everything is successful. What do you mean by workflows, processes and triggers? – odedta Jul 5 '17 at 9:23
  • automatic sf tools and features, that can change state of SObject before committing to database. wokflow, process, apex trigger – Oleksandr Berehovskyi Jul 5 '17 at 9:47
  • @AlexanderBerehovskiy How do I check that please? – odedta Jul 5 '17 at 10:02
  • 1
    @odedta - The Salesforce Administrator of that org can tell you. If you have access you can review the debug logs to see where the field is being modified. – Eric Jul 5 '17 at 13:51
0

I saw the logs and I don't really understand what Salesforce is doing much, why it chose to insert Partially Paid instead of Donated but the solution I used was to create an update query which uses the id of the create query response and set the StageName field again to Donated.

$DonationUpdate = new stdClass();
$DonationUpdate->Id = $createResponse[0]->id;
$DonationUpdate->StageName = 'Donated';
$createResponse = $mySforceConnection->update(array($DonationUpdate), 'Opportunity');

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.