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
THustonTHuston 

AggregateResult class not in Partner.wsdl

Salesforce.com Partner Web Services API Version 18.0
Generated on 2010-04-07 13:35:56 +0000.

 

There is no AggregateResult in the Partner.wsdl I just generated.

 

I built it anyway and can run aggregate SOQL into a QueryResult, however the Field names are all "Double".

I'm hoping the AggregateResult class exists and has more info about the source function (MAX, MIN, AVG, ect) and Field (Ammount, ect) it was used on.

 

Any idea how to get it?  or how to get the source Field info?

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

There's no AggregateResult class in the partner.wsdl just like there's no Account or Contact class.

 

aggregate results will be returned as a regular partner SObject with the type element set to AggregateResult, and the any collection returning the columns you queried for.

All Answers

SuperfellSuperfell

There's no AggregateResult class in the partner.wsdl just like there's no Account or Contact class.

 

aggregate results will be returned as a regular partner SObject with the type element set to AggregateResult, and the any collection returning the columns you queried for.

This was selected as the best answer
THustonTHuston

So when I make this query:

QueryResult qr = binding.query("SELECT Name, MAX(Amount), MIN(Amount) FROM Opportunity GROUP BY Name");

 

When I traverse the objects, I get:

Name, expr0, expr1

with MessageElement Types

null, Double, Double

 

How can I detect that expr0 is a MAX function on Amount??

 

 

Here is the PartnerSamples example Java code I use to look at the QueryResult:

Ouput looks like this

null
Burlington Textiles Weaving Plant Generator
{http://www.w3.org/2001/XMLSchema}double
Double
235000.0
{http://www.w3.org/2001/XMLSchema}double
Double
235000.0

 

qr = binding.query("SELECT Name, MAX(Amount), MIN(Amount) FROM Opportunity GROUP BY Name");
int loopCount = 0;
boolean continueLoop = true;
while (continueLoop) {
	System.out.println("Results set " + new Integer(loopCount++).toString()	+ " - ");
	// process the query results
	for (int i = 0; i < qr.getRecords().length; i++) {
		SObject sOB = qr.getRecords()[i];
		if ( i == 0 )
			traverseQueryResult(sOB, "");
		for ( int loc = 0; loc < sOB.get_any().length; loc++){
			MessageElement mel = sOB.get_any()[loc];
			System.out.println(mel.getType());
			if ( mel.getType() != null ){
				System.out.println(mel.getObjectValue().getClass().getSimpleName());
				if ( mel.getObjectValue().getClass().getSimpleName().equalsIgnoreCase( "SObject" ) ){
					SObject sOB2 = (SObject)  mel.getObjectValue();
					System.out.println( sOB2.getType() );
				}else if ( mel.getObjectValue().getClass().getSimpleName().equalsIgnoreCase( "QueryResult" ) ){
					QueryResult qryR = (QueryResult) mel.getObjectValue();
					SObject sub = qryR.getRecords(0);
					for ( int sloc = 0; sloc < sub.get_any().length; sloc++){
						MessageElement smel = sub.get_any()[sloc];
						System.out.println(smel.getValue());
					}
					int size = qryR.getSize();								
					int recLen = qryR.getRecords().length;
					System.out.println("Size=" + size + "    RecordsLen=" + recLen);

					while ( ! qryR.isDone() ){
						//size != recLen
						qryR = binding.queryMore( qryR.getQueryLocator() );
						size = qryR.getSize();
						recLen = qryR.getRecords().length;
						System.out.println("Size=" + size + "    RecordsLen=" + recLen);
					}
				}else if ( mel.getObjectValue().getClass().getSimpleName().equalsIgnoreCase( "Double" ) ){
					System.out.println(mel.getValue());								
					//SObject sOB2 = (SObject)  mel.getObjectValue();
					//above produces Exception ==
					//java.lang.ClassCastException: java.lang.Double cannot be cast to com.sforce.soap.partner.sobject.SObject										}
			}else{
				//it's a Field, print the value
				System.out.println(mel.getValue());
			}
		}
	}
	// handle the loop + 1 problem by checking to see if the most
	// recent queryResult
	if (qr.isDone())
		continueLoop = false;
	else
		qr = binding.queryMore(qr.getQueryLocator());
}
System.out.println("\nQuery succesfully executed.");

 

 

 

 

 

SuperfellSuperfell

You can't tell what sort of expr was used in the query from the results.

THustonTHuston

I guess that saves me time.  I simply cannot upgrade away from v17 and the users can suck it.

forceAMPforceAMP

What's worse is if you use an alias name that matches a field name in that object.  There's no way to detect the difference in the response xml between a value for a field of that object or an aggregate function value whose alias is that name without basically building a SOQL parser and aligning the Select list with the xml response.

 

What is needed is an attribute in the output that indicates this field result is the result of an aggregate function. Without aliases, you could look for exprXXX.  With aliases, you better get started on your SOQL parser :).

 

Just my 2 cents.

 

Bill