+ Start a Discussion
LearnSFDCLearnSFDC 

Can we get a reference object using a single query using WSDL

I am using the salesforce partner WSDL and my requirement is to get the RecordType Description from the Case Object. My code is as below

 

SoapBindingStub binding=sf.getBindingBySessionId(sessionId, sfURL);
String soql="Select c.RecordTypeId From Case c where c.Id='"+caseId+"'";
QueryResult qr2=binding.query(soql);
for (int j = 0; j < qr2.getSize(); j++) {
	SObject record1 = qr2.getRecords()[j];
	MessageElement[] elements1 = record1.get_any();
	if (null != elements1) {
		for (int k = 0; k < elements1.length; ++k) {
			if (elements1[k].getName() == "RecordTypeId") {
				recordTypeId=((String) elements1[k].getValue() == null ? ""
								: (String) elements1[k].getValue());
				break;
			}
		}
	}

}

String soql1="Select r.Description From RecordType r where r.Id='"+recordTypeId+"'";
QueryResult qr=binding.query(soql1);
for (int j = 0; j < qr.getSize(); j++) {
	SObject record1 = qr.getRecords()[j];
	MessageElement[] elements1 = record1.get_any();
	if (null != elements1) {
		for (int k = 0; k < elements1.length; ++k) {
			System.out.println(elements1[k].getName());
			if (elements1[k].getName() == "Description") {
				caseType=((String) elements1[k].getValue() == null ? ""
								: (String) elements1[k].getValue());
			}
		}
	}

}

 

 I am ending up doing 2 queries instead of a single query as RecordType is lookup for the case object.Here when i do a RecordType.Description in my first Query i get only the RecordType object and i am not able to extract Description out of it and hence using the additional second query.

 

Is there way to use a single query and get the result. I am new to Salesforce and maybe i am missing some Syntax here.Looked up online but could not get any such examples.

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

The recordType element contains a nested element for the description, so you need to get the recordType element, then find its child description element, and then get the text of that element.

All Answers

jhenningjhenning

Try this:

 

 

Select c.RecordType.Description From Case c where c.Id='"+caseId+"'";

 

 

LearnSFDCLearnSFDC

Hi,

   This is the first query i tried.Though this query runs fine in soql here the query returns only the RecordType and when i do a elements1[k].getName() from the MessageElement i get only RecordType as the name and the elements1[k].getValue() returns null.How do i get the Description from the RecordType?Maybe i am missing something here.

SuperfellSuperfell

The recordType element contains a nested element for the description, so you need to get the recordType element, then find its child description element, and then get the text of that element.

This was selected as the best answer
LearnSFDCLearnSFDC

Thanks Simon.It was a simple solution.I am new to WSDL.I had to work a bit for the solution but it turned out to be straight forward in the end.