You need to sign in to do that
Don't have an account?
pathworks
Can I query for the Name of an arbitrary object type?
Using the API, can I query for the Name of an arbitrary object, given only its id?
I'm trying to workaround the bug in the HYPERLINK formula where I cannot pass a text field (such as {!Name}) to my application (because of the lack of URL encoding). Therefore, I'm trying to pass only the object id. This could be for any object type. I then plan to retrieve the name using the API.
Is there a generalized way to do this? It could be for any object type (custom or not). I tried having the "object type" passed in on the query string, and doing a
QueryResult [] qr = binding.query("select Name from " + objecttype + " where id = '" + id + "');
However, the returned SObject type does not have a Name property, and I can't dynamically cast it to something that does, as it could be any custom object.
I'm currently tinkering which trying to grab it from the raw XML, maybe by using the getSerializer() method...but am not sure how much luck I'll have.
Thanks,
Dan
Message Edited by pathworks on 08-02-2006 10:19 AM
Message Edited by pathworks on 08-02-2006 10:19 AM
I switched to the partner API, and it looks to be much easier - getting the name field from describeSObject, and then getting the value with getAny()[0].getValue(). Thanks!
Dan
SObject [] objects = qr.getRecords();
if (objects == null || objects.length != 1) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No object with id " + id + " found.");
return;
}
MessageElement [] elems = objects[0].get_any();
if (elems == null || elems.length != 1) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No properties returned on object.");
}
String name = elems[0].getValue();
Message Edited by pathworks on 08-02-2006 05:23 PM
Ok - the lead had an empty first name. When I change the code to grab multiple name fields and concatenate them it will fix this (currently the code just picks the "last" name field from the for loop). Which order should I concatenate them in?
Thanks,
Dan
Aha - locale specificity was my "next question". I guess I'll just append them in a random order and hope for the best.
Thanks,
Dan