You need to sign in to do that
Don't have an account?
shurik
'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
// 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
<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>
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).
// 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
How to check in doc what we could ?
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.
We are getting Endpoint URL through API_Partner_Server_URL_70 parameter from Salesforce.
Could we hardcode enterprise Endpoint in our code ?
Thanks for All