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?
workflows, processes and triggers
?