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
anksphenomenonanksphenomenon 

No such column 'fields' on entity 'contact'. error while upserting a Contact

Hello guys,

I am trying to upsert a new account in to the sales force database. I have a custom wrapper function to do this in our system. Here is my code:

function sf_insertData($ArrData)
{
    global $mySforceConnection, $mySoapClient, $mylogin, $ArrErrMsgs;
    $sObject = new sObject();
    $sObject->type = 'Contact';
   
// No Need to see this code
    $ArrData['fields'] = array_combine(sf_mapSfFields(array_keys($ArrData['fields']),$ArrData['type']), array_values($ArrData['fields']));



    $sObject->fields = $ArrData['fields'];

    $result = $mySforceConnection->upsert('AccountId', array($sObject));
    return $result;
}

With all the processing, I ultimately have this Object that goes into the upsert call:

SObject Object
(
[type] => Contact
[fields] => Array
(
[FirstName] => Ankit Chbbad
[Phone] => 123456
[AccountId] => 0014000000Id67gAAB
)

)

When i run this code I get this error:


Fatal error: Uncaught SoapFault exception: [sf:INVALID_FIELD] INVALID_FIELD: No such column 'fields' on entity 'contact'. in /home/.trine/ibc2007/beta.illinoisbusinessconsulting.com/salesforce/soapclient/SforceBaseClient.php:396 Stack trace: #0 [internal function]: SoapClient->__call('upsert', Array) #1 /home/.trine/ibc2007/beta.illinoisbusinessconsulting.com/salesforce/soapclient/SforceBaseClient.php(396): SoapClient->upsert(Object(stdClass)) #2 /home/.trine/ibc2007/beta.illinoisbusinessconsulting.com/salesforce/soapclient/SforceEnterpriseClient.php(93): SforceBaseClient->_upsert(Object(stdClass)) #3 /home/.trine/ibc2007/beta.illinoisbusinessconsulting.com/salesforce/soapclient/sf_functions.php(169): SforceEnterpriseClient->upsert('AccountId', Array) #4 /home/.trine/ibc2007/beta.illinoisbusinessconsulting.com/salesforce/soapclient/sf_functions.php(41): sf_insertData(Array) #5 {main} thrown in /home/.trine/ibc2007/beta.illinoisbusinessconsulting.com/salesforce/soapclient/SforceBaseClient.php on line 396



what's wrong here?? I have kinda hit my head enuf on the walls :(
Park Walker (TAGL)Park Walker (TAGL)
Make sure that you are using the Partner WSDL file and endpoint when making your connection. The Enterprise WSDL does not use the 'fields' array and would probably produce an error message like this.

Also, if you are doing an 'upsert' then you will need to have the external id field in the object that you send. It doesn't look like that's the case here. Unless you have identified the external id field in the record definition you should be using 'insert' rather than 'upsert' to add a new record.

Park

Message Edited by Redsummit on 07-22-2008 11:32 AM
ClimbatizeClimbatize
Hi there, I'm experiencing the same problem. I use the enterprise wdsl. there is my code:

My connexion functions:

Code:

define("SOAP_CLIENT_BASEDIR", "phptoolkit-13_0/soapclient");


require_once (SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php');
require_once (SOAP_CLIENT_BASEDIR.'/SforceHeaderOptions.php');
require_once ('phptoolkit-13_0/userAuth.php');
function ConnectSession($USERNAME,$PASSWORD)
{

 /////////////////////////Time
 //$chrono = start_chrono();
 try {
   $mySforceConnection = new SforceEnterpriseClient();
   $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
   $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
   $_SESSION['connexion'] = $mySforceConnection;

   $_SESSION['location'] = $mySforceConnection->getLocation();
  $_SESSION['sessionId'] = $mySforceConnection->getSessionId();
  $_SESSION['wsdl'] = SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml';
   
 } 
 catch (Exception $e) 
 {
   echo $mySforceConnection->getLastRequest();
   echo $e->faultstring;
 }
 /////////////////////////EndTime
 //echo  end_chrono($chrono,"ConnectSession");
}

function reconnect()
{
 $location = $_SESSION['location'];
 $sessionId = $_SESSION['sessionId'];
 $wsdl = $_SESSION['wsdl'];

 $mySforceConnection = new SforceEnterpriseClient();
 $sforceSoapClient = $mySforceConnection->createConnection($wsdl);
 $mySforceConnection->setEndpoint($location);
 $mySforceConnection->setSessionHeader($sessionId);
 
 $_SESSION['connexion'] = $mySforceConnection;
}

 

My upsert code on a custom object:

Code:
reconnect();

$sObject1 = new stdClass();
$sObject1->Comment__c = $_GET['comments'];
$sObject1->Id = $_GET['id'];
$sObject1->type = 'Test_Case__c';


try
{

$response = $_SESSION['connexion']->upsert('Comment__c',array ($sObject1));

}
catch(Exception $e)
{
echo "<font color=red weight=bold>Update FAILED</font>";
echo "<b>erreur!</b> ".str_replace("\n","<br><br>",$e);

}

 and the response:

Code:
erreur! SoapFault exception: [sf:INVALID_FIELD] INVALID_FIELD: No such column 'Comment__c' on entity 'contact'. in C:\Dev\Workspace\CnV\phptoolkit-13_0\soapclient\SforceBaseClient.php:419

Stack trace:

#0 [internal function]: SoapClient->__call('upsert', Array)

#1 C:\Dev\Workspace\CnV\phptoolkit-13_0\soapclient\SforceBaseClient.php(419): SoapClient->upsert(Object(stdClass))

#2 C:\Dev\Workspace\CnV\phptoolkit-13_0\soapclient\SforceEnterpriseClient.php(93): SforceBaseClient->_upsert(Object(stdClass))

#3 C:\Dev\Workspace\CnV\post.php(34): SforceEnterpriseClient->upsert('Comment__c', Array)

#4 {main}

Why does uspert tries to update the contact object instead of my custom one?