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
benvbenv 

Custom Formula field in SOQL query, describeSObject, PHP

I can't query a custom formula field in the product2 object. I don't get an error when I put it in the SOQL SELECT statement, but I can't select it. I can select it from the Excel Connector, so it must be possible. Code:
$query_all_products = "select Id, ProductCode, Quantity__c, Warehouse_Location__c, WeightOunces__c, Shipping_Weight_Formula__c from product2";
$result = $sforce->query(array("queryString" => $query_all_products));
$all_products=$result->result->records;
echo '<pre>'.print_r($all_products,true).'</pre>';
Warehouse_Location__c
doesn't show up in the resulting object.And when I try using describeSObject:
$contact= $sforce->describeSObject("Contact");
print_r($contact);
I get this error: Fatal error: Uncaught SoapFault exception: [sf:INVALID_TYPE] INVALID_TYPE: sObject type cannot be null in (filename):3 Stack trace: #0 [internal function]: SoapClient->__call('describeSObject', Array) #1 (filename)(3): SoapClient->describeSObject('Contact') #2 {main} thrown in (filename) on line 3 Any ideas?
msimondsmsimonds
benv

I think you just need some small adjustments in your code:

try this code (make sure you change the query):

Code:
$query_all_products = "Select Id, Name, BillingCity, BillingState From Account";
$queryOptions = new QueryOptions(500);
$response = $sforce->query(($query_all_products), $queryOptions);
$all_products = $response->records;
echo '<pre>' . print_r($all_products, true) . '</pre>';

 

msimondsmsimonds
Also I forgot to add that your original query is pulling from the product2 object

and your describeObject is going against the Contact object.

So you will never see your custom field:

Maybe try this utlitity script that I posted on my site


benvbenv
The two pieces of code I posted were two separate scripts, two separate problems. I have run many SOQL queries with PHP. I'm not getting an error from the one where I'm trying to select the custom formula field Shipping_Weight__c, it's just that the field doesn't show up in any of the results, even though I can pull values from that field using the Excel Connector. So your response didn't really address the issue of the missing formula field in the query results.

And on my describeSObject example, I used Contact just to show that it has nothing to do with a custom object or custom fields, I simply can't get describeSObject to work no matter what.

When I tried using your describeGlobal example, it just said that $result->types was an invalid argument for foreach.

Maybe something wrong w/ my wsdl or connection script? Even though I've had a lot of query/update/delete scripts working for months...

Here's the connection script.
Code:
// Connect
$sforce = new SoapClient("sforce.wsdl");  // obtain your own customized sforce.wsdl from sforce.com
$loginResult = $sforce->login(array("username" => "my@email.com", "password" => "password"));
$loginResult= $loginResult->result;

// Set connection data
$sforce->__setLocation($loginResult->serverUrl);
$sforce_header = new SoapHeader('urn:enterprise.soap.sforce.com', 'SessionHeader', array('sessionId' => $loginResult->sessionId));
$sforce->__setSoapHeaders(array($sforce_header));

 


So msimonds, I very much appreciate the response, but I'm still right where I started.

msimondsmsimonds
Sorry I could not help, but also let me suggest a few things.

1) In your first post, you never stated that they were two separate problems, they looked like they were tied together.

2) Something must be wrong with your setup because the describeGlobal example that I showed you works fine on 3 different servers that I use for development

    a) did you change your php version lately
    b) maybe something is wrong with your wsdl (as you stated), try getting a new partner wsdl file > especially    since you stated that you have run lots of queries.


Anyway best of luck, I hope that you get your problems corrected

~Mike
benvbenv
A new piece of the puzzle.

I added a checkbox field called Always_Ship_UPS__c to the product2 object. I downloaded a new enterprise WSDL (since I currently only develop for one organization). I finally got a describeSObject() call to work:
Code:
$product2= $sforce->describeSObject(array("sObjectType"=>"product2"));
(previously I was just trying $sforce->describeSObject("product2") which didn't work.)

The new field Always_Ship_UPS__c shows up in the describeSObject() result. I also successfully updated the field using $sforce->update().

But when I put it in the field list of a SELECT statement, I don't get an error, but it never shows up in my result, whether or not the field has a value in Salesforce. This is the same thing that happened previously when I tried querying a custom formula field.

Any ideas?

Message Edited by benv on 10-15-2007 04:21 PM

tlaappdev1tlaappdev1
previously I was just trying $sforce->describeSObject("product2") which didn't work.)

The new field Always_Ship_UPS__c shows up in the describeSObject() result. I also successfully updated the field using $sforce->update().

But when I put it in the field list of a SELECT statement, I don't get an error, but it never shows up in my result, whether or not the field has a value in Salesforce. This is the same thing that happened previously when I tried querying a custom formula field.

Any ideas?

Message Edited by benv on 10-15-2007 04:21 PM


I have this problem exactly several feilds just can not be selected. I ahve the most current WSDL they appear as objects with a describeSObject() but no columns are returning. Hell I even did a SELECT Id,fieldname from Account where Id='basdfasd' and it returned this


object(stdClass)#7 (4) {
["done"]=>
bool(true)
["queryLocator"]=>
NULL
["records"]=>
array(1) {
[0]=>
object(stdClass)#12 (1) {
["Id"]=>
string(18) "basdfasd"
}
}
["size"]=>
int(1)
}

as you see no feildname field is listed here this totally sucks

apaatsioapaatsio
I had similar problems as the original poster. SELECT query didn't return data for custom fields. Updating the WSDL files worked for me, thank you!
James W.ax741James W.ax741

Salesforce not displaying Custom Fields when perform SELECT statement QUERY for the API

(excuse all the key words, just helping people find it)

After a day of searching and finding various answers, this is the solution I found to solve the issue with not being able to actually see the values of custom fields in SELECT statements for Saleforce Queries.

 

Step 1: Make sure you have updated your WSDL XML file after you create any new custom fields

 

From within Salesforce:

> Setup > Develop > API

Generate Enterprise WSDL (or Partner WSDL) which ever applies to your personal needs

Save the newly created WSDL XML file over top of your existing WSDL file (generally found under /SOAPCLIENT/

 

If this solves your problem. GREAT! If not, try the next step.

 

Step 2: Make sure your WSDL file is not being cached, by using the following PHP code:

I also included this prior to creating my Salesforce Connection, to prevent WSDL caching.

 

ini_set("soap.wsdl_cache_enabled", "0"); 
Rent2wayRent2way
James W, thank you so much! It was in fact the caching of the WSDL that was causing issues after I had re-generated the WSDL to accommodate the new custom fields. Save me much headache, thank you!