+ Start a Discussion
shurikshurik 

'User' retrieve problem

We could not get additional user info (phone, mobilePhone) by using 'retrieve' function for object 'User' by UserID. We could emulate a request to your server by hand coding some XML and the server seems to return a good response. This is the code:

// retrieve
SObject[] sObjects = binding.retrieve("Phone, MobilePhone", "User", new String[] {userInfo.getUserId()} );
if (sObjects != null) {
   User sUser = (User)sObjects[0];
   // sUser.getPhone();
   // sUser.getMobilePhone();
}

The request returns without exceptions, but returned value in sObjects is wrong .
sObjects should contain 1 User object returned but it contains 4 or 5 wrong null objects 
SuperfellSuperfell
You're probably on Axis 1.2.1 which appears to have a bug in this area. Try a newer version of Axis (You can confirm this by examining the raw soap response, which you should see only have a single user in it)
shurikshurik
We are using Axis 1.3, October 5 2005
SuperfellSuperfell
Compare the SOAP response vs what axis says it is.
shurikshurik
I'm trying to debug public com.sforce.soap.enterprise.sobject.SObject[] retrieve(java.lang.String fieldList, java.lang.String sObjectType, java.lang.String[] ids) I have here... java.lang.Object _resp = _call.invoke(new java.lang.Object[] {fieldList, sObjectType, ids}); _resp contains array of 5 SObjects How should I debug ?
SuperfellSuperfell
Use one of the of http tracing tools (tcpmon, tcpTrace, SOAPScope) to confirm that there's only one user row in the response, then you know its an axis problem (you should probably try axis 1.4 as well). If its an axis problem, you'll need to log a bug with the axis folks.
shurikshurik
request

<soapenv:Body>
 - <retrieve xmlns="urn:enterprise.soap.sforce.com">
      <fieldList>Phone, MobilePhone</fieldList>
      <sObjectType>User</sObjectType>
      <ids>00530000000vTIIAA2</ids>
   </retrieve>
 </soapenv:Body>

response

<soapenv:Body>
 - <retrieveResponse>
    - <result xsi:type="sf:sObject">
         <sf:type>User</sf:type>
         <sf:Id>00530000000vTIIAA2</sf:Id>
         <sf:Phone>(650) 465-3762</sf:Phone>
         <sf:MobilePhone>(408) 282-3602</sf:MobilePhone>
         <sf:Id>00530000000vTIIAA2</sf:Id>
      </result>
   </retrieveResponse>
</soapenv:Body>

also why twice

<sf:Id>00530000000vTIIAA2</sf:Id>

SuperfellSuperfell
Response looks fine, I'd try axis 1.4, if that's still not working, you'll need to a log a bug with the axis folks. http://ws.apache.org/axis  (you can also work around this by using query instead of retrieve)

The id appears twice because of the combination of the WSDL and the partner API. The first Id element is the Id that's defined in the base sObject definition, the 2nd Id element is there so that in all cases the number and order of elements in the response that are mapped into the any collection matches the fields asked for in the query. This makes it easy to index into the any collection to get the data for a specific field. (This is the theory, there are some bugs in various versions of axis that make this not work correctly, I think i posted a couple of articles on the sforce blog about this).

shurikshurik
Could I query User by Id ?
SuperfellSuperfell
Yes, select [fields] from user where id='the_users_id'
shurikshurik
code

// query
QueryResult qr = null;
QueryOptions qo = new QueryOptions();
qo.setBatchSize(new Integer(1));
binding.setHeader(new SforceServiceLocator().getServiceName() .getNamespaceURI(),
    "QueryOptions", qo);

qr = binding.query("select Phone, MobilePhone from User where Id='" + userInfo.getUserId() + "'");
if (qr.getRecords().length > 0) {
   User sUser = (User)qr.getRecords()[0];
   // sUser.getPhone());
   // sUser.getMobilePhone());
}

request

 <soapenv:Body>
 - <query xmlns="urn:enterprise.soap.sforce.com">
  <queryString>select Phone, MobilePhone from User where Id='00530000000vTIIAA2'</queryString>
  </query>
 </soapenv:Body>

response

- <queryResponse>
  - <result xsi:type="ns1:QueryResult">
    <ns1:done>true</ns1:done>
    <ns1:queryLocator xsi:nil="true" />
    - <ns1:records xsi:type="sf:sObject">
      <sf:type>User</sf:type> <sf:Id xsi:nil="true" />
      <sf:Phone>(650) 465-3762</sf:Phone>
      <sf:MobilePhone>(408) 282-3602</sf:MobilePhone>
     </ns1:records>
   <ns1:size>1</ns1:size>
  </result>
 </queryResponse>

code throws exception on line
qr = binding.query("select Phone, MobilePhone from User where Id='" + userInfo.getUserId() + "'");

exception is

Invalid element in ...SObject
SuperfellSuperfell
Don't send enterprise API requests to the partner API endpoint. (also loose the batchSize setting to 1, it'll only make things slower)
shurikshurik
Does it mean that we could not get additional user info ?

How to check in doc what we could ?
SuperfellSuperfell
Its just means you're mixing stuff up you shouldn't. The query you're running can be run equally well via the enterprise API or the partner API.

Your code appears to be written using the enterprise API, but the response is clearly (to me anyway :smileyhappy: ) from the partner API. If you want to use the enterprise API, you need to send your requests to the enterprise endpoint (ends with /c/7.0) not the partner endpoint (ends with /u/7.0) If you want to use both APIs at the same time, you need to be careful to manage the 2 endpoints seperately.
shurikshurik
Well, seems You are right. Sorry for that.

We are getting Endpoint URL through API_Partner_Server_URL_70 parameter from Salesforce.
Could we hardcode enterprise Endpoint in our code ?
SuperfellSuperfell
Just use API_Enterprise_Server_URL_70 instead.
shurikshurik
Now it works.
Thanks for All