
Originally Posted by
CountRugen
Hi Mike,
great site. Very helpful!
I used the thread at
http://www.mikesimonds.com/update-co...ption-t89.html
to help me run update commands, with a few minor modifications.
Here's what I am running:
PHP Code:
ini_set("soap.wsdl_cache_enabled","0");
$username = 'my@email.com';
$password = 'mypassword';
$date = date("m/d/y");
require_once ('../includes/soapclient/SforceEnterpriseClient.php');
$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient = $mySforceConnection->createConnection("../includes/soapclient/enterprise.wsdl.xml");
$mylogin = $mySforceConnection->login($username,$password);
try
{
if ($mylogin) {
$query = "select Id";
$query .= " from Account";
$query .= " where Account.WebID__pc=22";
$queryResult = $mySforceConnection->query($query);
$records = $queryResult->records;
foreach ($records as $record)
{
echo '<pre>' . print_r($record,true) . '</pre>';
//$sObjectContact = new sObject();
$sObjectContact->type = 'Account';
$sObjectContact->Id = $record->Id;
$sObjectContact->fields = array('FirstName' => 'Shano');
print_r($sObjectContact);
$result = $mySforceConnection->update(array($sObjectContact));
// print_r($result);
if ($result->success)
{
echo "good";
}
else
{
echo "bad";
}
}
}
else
{
echo "crap, something is wrong";
}
}
catch (exception $e)
{
echo $mySforceConnection->getLastRequest();
echo $mySforceConnection->getLastRequestHeaders();
echo '<pre>' . print_r($e,true) . '</pre>';
}
and when I do I get the following error to my browser. Can you help me work out what needs to be done to overcome this?
Warning: Missing argument 2 for SforceEnterpriseClient::update(), called in /mounted-storage/home94a/sub004/sc49409-VDPR/www/member/member4.php on line 30 and defined in
/mounted-storage/home94a/sub004/sc49409-VDPR/www/includes/soapclient/SforceEnterpriseClient.php on line
68
462200D70000000Ij6O!AQkAQN31N.N3Gevi0l18_N8u3NY1pK GBi4JvGiePTVyZzvzBEuJr0WUAaXDQj.Va0AaxO8rohbTOBWMH k7Ij9jdCNIBGdmT8Contact0017000000NqhHZAAZFirstName Shano POST /services/Soap/c/13.0/462200D70000000Ij6O HTTP/1.1 Host: na5-api.salesforce.com Connection: Keep-Alive User-Agent: PHP-SOAP/5.2.3 Accept-Encoding: gzip, deflate Content-Type: text/xml; charset=utf-8 SOAPAction: "" Content-Length: 604
Thanks
Count Rugen
Well let me see where I can begin:
First off thanks for joining the site and thanks for the comments. I hope you find the information here helpful
There are a few things that need to be tweaked in your code
First off look at your query:
PHP Code:
$query = "select Id";
$query .= " from Account";
$query .= " where Account.WebID__pc=22";
If this is a custom field, it has to end in a "__c" NOT "__pc", as you have.
I changed it to
PHP Code:
$query = "select Id";
$query .= " from Account";
$query .= " where Account.WebID__c = '22'";
Second I do not use the Enterprise Client, I only use the Partner Client... As you will see in that post that I helped the other member on
Also
there is no field on the Account object > FirstName, that is only in the contacts and user objects
I added a field WebID__c to my developers org and ran the following script, once I updated the new field with a value of '22'
PHP Code:
<?php
ini_set("soap.wsdl_cache_enabled","0");
$username = 'masimonds@gmail.com';
$password = 'mas4155yrQkDd4rzC3qZE8cydu6goAHe';
$date = date("m/d/y");
require_once ('./soapclient/SforcePartnerClient.php');
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection("./soapclient/partner.wsdl.xml");
$mylogin = $mySforceConnection->login($username,$password);
try
{
if ($mylogin)
{
$query = "select Id";
$query .= " from Account";
$query .= " where Account.WebID__c = '22'";
$response = $mySforceConnection->query($query);
$queryResult = new QueryResult($response);
foreach ($queryResult->records as $record)
{
echo '<pre>'.print_r($record,true).'</pre>';
$sObjectContact = new sObject();
$sObjectContact->type = 'Account';
$sObjectContact->Id = $record->Id;
$sObjectContact->fields = array('maxim_id__c' => '987654321');
$result = $mySforceConnection->update(array($sObjectContact));
if ($result->success)
{
echo "good";
}
else
{
echo "bad";
}
}
}
else
{
echo "crap, something is wrong";
}
}
catch (exception $e)
{
echo $mySforceConnection->getLastRequest();
echo $mySforceConnection->getLastRequestHeaders();
echo '<pre>'.print_r($e,true).'</pre>';
}
?>
and ran it, you can too, I will leave my login information in there for you to mess around with.
Since you are asking for only one item in Salesforce, You needed to change your foreach loop, since it is only one record:
PHP Code:
$queryResult = new QueryResult($response);
foreach ($queryResult->records as $record)
{
try the whole script as I posted it and tell me if that works for you, I hope it does and try the Partner client to see if it fits your needs. I am sure it will
I really do not see why anyone would need to use the Enterprise client when everything can be done with the partner
Anyway I hope that helps
~Mike
Bookmarks