You need to sign in to do that
Don't have an account?
Is there a general technique for manually deserializing a QueryResult ?
The question really is: How to go about deconstructing and extracting data from a QueryResult which is totally based on a custom object ?
Is there a general technique for manually deserializing a QueryResult where the entire query result comes from an SForce custom-object ? Any advice or samples would be appreciated...
I am looking for some general guidance / guidelines on how to extract the name / value pairs (roughly the SFDC equivalent of columns and values) from a query result.
Is SObject.get_any() [indice].getValue() probably the best mechanism available ?
The main issue being -- I am retrieving the contents of a 100% custom object (all of the fields end with '__c') using the Partner 6.0 API without a WSDL.
There is a reason for not using a WSDL -- We don't necessarily know the structure of the custom object - (it may have been further customized by a client) - So I am first retrieving the structure of the custom object with a call to DescribeSObject:
DescribeSObjectResult dsor = binding.describeSObject(objs[h]);
Field[] fields = dsor.getFields();
// Then extracting the field names...
if (fields != null) {
String fieldnames[] = new String[fields.length];
// Iterate through the fields to get properties for each field
for (int i = 0; i < fields.length; i++) {fieldnames[i] = fields.getName();
}}
// Then -- based on the field list -- generate a dynamic SOQL query by joining the field names
String SOQL = "SELECT " + join(", ", fieldnames) + FROM " + dsor.getName() + "");
QueryResult qr = this.binding.query(SOQL);
You should use the get_any() loop.
private JSONArray SFDCQuery(String target, String SOQL) {
this.message("DMSFCommissions::SFDCQuery(" + SOQL + ") -> Called...");
// LOCALS...
QueryResult qr = null;
_QueryOptions opts = new _QueryOptions();
opts.setBatchSize(new Integer(2000));
JSONArray rs = new json.JSONArray();
// APPLY THE QUERY OPTIONS TO THE HEADER...
this.binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(), "QueryOptions", opts);
try {
// EXECUTE THE SOQL STATEMENT...
qr = this.binding.query(SOQL);
// FOR EVERY RECORD THAT IS RETURNED...
for (int r = 0; r < qr.getSize(); r++) {
// PUT THE SFORCE RECORD INTO OUR "pseudo-rowset"...
JSONObject row = new json.JSONObject();
SObject so = qr.getRecords()[r];
org.apache.axis.message.MessageElement[] me = so.get_any();
// this.message("Record is of type: " + so.getType());
// PUT THE SFDC PRIMARY (sic) KEY IN THE ROW...
row.put("ID", so.getId());
// LOOP THROUGH THE ROW-SET...
for (int c = 0; c < me.length; c++) {
// PUSH THE KEY-VALUE INTO THE STACK...
row.put(me[c].getName(), me[c].getValue());
}
// PUT THE "pseudo-rowset" INTO THE GLOBAL "pseudo-recordset"...
rs.put(r, row);
}
} catch (UnexpectedErrorFault uef) {
super.Error("DMSFCommissions::SFDCQuery() -> Unexpected Error Fault:", uef.getExceptionMessage());
} catch (Exception ex) {
super.Error("DMSFCommissions::SFDCQuery() --> Exception:", ex.getMessage());
}
return rs;
}