You need to sign in to do that
Don't have an account?
Milkovic
Retrieving the value of a custom field using Partner API
QueryResult qr = binding.query("select Name, Money__c from account");
SObject account = qr.getRecords()[0];
MessageElement[] fields = account.get_any();
System.out.println(fields.length);
System.out.println(fields[0].getAsDOM().getChildNodes().item(0).toString());
Using this code only 1 field ("Name") is returned. How do get the value of my custom field ("Money__c") using the partner API?
Thanks
Hi WhizA,
I hop I'm not being obvious here, but, fields[0] will always return only the 0th element of the fields array. How about trying
for (int i=0;i<fields.length;i++) {
System.out.println(fields[i].getAsDOM().getChildNodes().item(0).toString());
}
??
Hey Dave,
I saw that in the examples, but my problem is fields.length = 1 when I'm selecting from 2 fields. Any ideas?
Hi WhizA,
So, what is happening is that axis is filtering out values that are nil. If you capture the SOAP response, you will see your custom field in the message and it will look something like this:
<records>
<type>Contact</type>
<ns5:Id xmlns:ns5="urn:sobject.partner.soap.sforce.com">00330000001oAFIAA2</ns5:Id>
<ns6:LastName xmlns:ns6="urn:sobject.partner.soap.sforce.com">Blow</ns6:LastName>
<ns7:FirstName xmlns:ns7="urn:sobject.partner.soap.sforce.com">Joe</ns7:FirstName>
<ns8:Test__c xsi:nil="true" xmlns:ns8="urn:sobject.partner.soap.sforce.com"/>
</records>
Assuming my FirstName and LastName fields have values, the any array will have a length of 2.
Compare to this response fragment:
<records>
<type>Contact</type>
<ns9:Id xmlns:ns9="urn:sobject.partner.soap.sforce.com">00330000001oAFJAA2</ns9:Id>
<ns10:LastName xmlns:ns10="urn:sobject.partner.soap.sforce.com">Blow</ns10:LastName>
<ns11:FirstName xmlns:ns11="urn:sobject.partner.soap.sforce.com">Joe</ns11:FirstName>
<ns12:Test__c xmlns:ns12="urn:sobject.partner.soap.sforce.com">One</ns12:Test__c>
</records>
Making the same assumptions, the any array for this record will have a length of 3.
There may or may not be a configuration setting to tell Axis not to exclude nulls (nils) from the serialized object.
Cheers