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
lwisnelwisne 

cannot access custom fields on custom objects via api

I have a custom object in our Salesforce setup called AgentProducts, when I do a query (code running in php) via the API the only field I can get back is Id;

 

select Id, User_Id__c from AgentProducts__c

 

returns a record for every one of the entries in AgentProducts, but only with the Id field;

Array
(
    [0] => stdClass Object
        (
            [Id] => a0350000008xWWKAA2
        )

    [1] => stdClass Object
        (
            [Id] => a0350000008xWWLAA2
        )
etc. 

 

Even worse, if I filter the query by something like my custom email field, I get back the correct Id for the correct account, but still, no further data;

select Id, User_Id__c from AgentProducts__c where Email__c='xxx@xxxxx.xxx'

 

returns:

stdClass Object
(
    [Id] => a0350000008xWWMAA2
)

 

Any ideas?  I've been looking through the online documentation but I can't find anything on custom objects needing special treatment.

 

Park Walker (TAGL)Park Walker (TAGL)
Have you checked to be sure that the permissions on the object fields allow access by the user being used in the API?
lwisnelwisne

Thanks for your reply.

 

I have checked the permissions.  What I checked was under 

Administration Setup ->

 Manage Users ->

   Profiles

    Then the particular profile is the Admin,and under his Custom Object Permissions all of the check boxes (Read, Create, Edit, Delete, View All, Modify All) are checked off.

 

Are these the permissions you mean?  

 

I also noticed that some other threads on similar topics recommended  updating the enterprise WSDL.  We did that as well but I am still having the same problem.

 

this query returns a record with an ID that is correct for the email

select Id, Email__c, User_Id__c from AgentProducts__c where Email__c='xxxx@xxxx.com'

but it only returns the Id.

 

thank you for your help

Message Edited by lwisne on 06-25-2009 05:05 PM
jhilgeman3jhilgeman3
I'm having this exact same problem right now, too. Permissions look right on the fields being selected, but the only field I get back is the Id field. Please help!
jhilgeman3jhilgeman3
Also, I'm using version 11.0 of the PHP toolkit, EnterpriseClient on a developer account, if that makes a difference.
jhilgeman3jhilgeman3

Got it to work.

 

The problem was that the WSDL file that comes with the Toolkit doesn't include all the custom object fields, so I needed a version of the WSDL file that had my custom objects in it - basically a "personalized" version of that file. I got it by going to Setup >> Develop >> API, and then there's an option to get the WSDL file. I was using the enterprise WSDL file, so I downloaded that version, and sure enough, it included all the custom objects and their fields.

 

I overwrote the old WSDL file (mine was in the soapclient folder) with it (I had to view the page source first to see the real content, since my browser tried to show me the file instead of downloading it) and then copied all of that content into the old WSDL file.

 

One small thing I noticed - if a field has not been filled in (for example, I had a set of optional custom fields that most records didn't use), then the field does not come back in the recordset, even if I explicity added that field into the SELECT query.

 

Hope this helps.

 

James W.ax741James W.ax741

Further to the above solution, you might also want to make sure that your WSDL is not caching by adding the following code before you create a Salesforce Connection through SOAP. This was the missing piece in my puzzle.

 

Not my solution, just pasting it everywhere where I found half the answer. Thanks all.

 

ini_set("soap.wsdl_cache_enabled", "0"); 

 

 

 

 

 

msimondsmsimonds

Also I would not use the Enterprise WSDL, I always use the partner WSDL. it is a lot more felxible!!

 

 

 

~Mike

henrynwhenrynw

Thank you so much for this!!!!!!!!!!!!!!!!!!!! I was going crazy trying to work out why I couldn't see my custom fields in the API. THANK YOU!

ranjeet.ax1557ranjeet.ax1557

<?php
// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.ocm password


define("SOAP_CLIENT_BASEDIR", "../soapclient");

 ini_set("soap.wsdl_cache_enabled", "0");


$USERNAME='ranjeet.ghola11ve@done.com';
$PASSWORD="ranjeet11donec10bhQzwkIQd28sWldfhmuYN2";

//require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');
require_once (SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php');
require_once (SOAP_CLIENT_BASEDIR.'/SforceHeaderOptions.php');

require_once (SOAP_CLIENT_BASEDIR.'/SforceBaseClient.php');

try
{
   $mySforceConnection = new SforceEnterpriseClient();
    $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
    $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);

   $query = "SELECT Id,FirstName,LastName,Email,Mychance__c FROM Contact";
$queryResult = $mySforceConnection->query($query);
$records = $queryResult->records;
 echo "<pre>";
  print_r($records);
   echo "</pre>";

 
} catch (Exception $e) {  
    echo "<pre>";print_r($e);echo "</pre>";
}
?>

can't get the custom value  of Mychance__c field .   And in contact that Mychance__c is also not empty.

 

 I use upadated enterprise file.

and also
 ini_set("soap.wsdl_cache_enabled", "0"); whats wrong in my code. i am using developer edition . Please Help

Web DepartmentWeb Department
Thank you, jhilgeman3, for your solution. Does anybody know if there's an easy way to keep this enterprise.wsdl.xml file up-to-date automatically? It would be very inconvenient to have to remember to re-download and replace this file every time a customization is needed.
Thanks!
rdjrdj
many thanks jhigelman3!
sajid shaikh 1sajid shaikh 1
if you are using partner wsdl then use current() to get all the fields, like this.

$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection('partner.wsdl.xml');
$mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
$query = "SELECT Id,Name__c,Phone__c from CustomObje__c;
$response = $mySforceConnection->query($query);
$queryResult = new QueryResult($response);
print_r($queryResult->current());


This will return single record entry, you can use it in loop as well to get all the records. This is working perfectly for me. 
 
Virath C. LiyanageVirath C. Liyanage
For Enterprise WSDL you can use in C#.NET:
sOBJECT.GetType().GetProperty(FIELDNAME.ToString()).GetValue(sOBJECT)

For partner WSDL you need to phase the XML which is described in sOBJECT.Any