function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tvignontvignon 

Using API update()

Hi all -

I've been working today on a simple PHP page that will record a user's response in a form and update a corresponding field on their account. I'm getting a success message from my update() code when I print_r, but I'm not actually seeing any updated information in my accounts. The code I have is as follows:


Code:
$prop = addslashes($_GET['prop']);
$rank = $_POST['NPS'];
 
$nps = new sObject();
$nps->type = 'Account';
$nps->Id = $prop;
$nps->fields = array('NPS_2__c' => '$rank', 'NPS_2_Date__c' => 'DATE');

print_r($mySforceConnection->update($nps)); 
echo "Thank you for your response. Your information has been submitted.";

 The ID is a known field that will be a passed variable in the URL. When the page is accessed and the form is submitted, I get the following print message:

stdClass Object ( [id] => 0017000000NoRVFAA3 [success] => 1 ) Thank you for your response. Your information has been submitted.

However, like I said, if I check the fields in the sObject on the Account page, they have not been updated. I know it's got to be something simple I'm overlooking, but it's Monday of course. Any help will be greatly appreciated.

Thanks!!

Travis Vignon

brodrigubrodrigu
It looks like this is an old post, but I am having the exact same problem.

Can anyone help us out, I have looked everywhere and I cannot find a solution to this problem.
tvignontvignon
brodrigu,

I made the original post and never got a reply, so I just had to figure it out for myself. It was actually really simple for me. The only change I had to make was in the update line:

Code:
$nps = new sObject();
$nps->type = 'Account';
$nps->Id = $prop;

$nps->fields['NPS_2__c'] = $rank;
$nps->fields['NPS_2_Date__c'] = $date;

$mySforceConnection->update(array($nps));

I had to wrap my $nps object in an array before it would update properly. If you read my original post, the update line looked like this:

Code:
print_r($mySforceConnection->update($nps));

 
You can see the only difference was wrapping the sObject in an array. Worked for me! Hopefully it will be that simple for you.