You need to sign in to do that
Don't have an account?
Chris987654321
Querying __r relationship fields
I am having trouble with doing relationship queries in C#. I'm using the Partner WSDL
string query = "select Account.Id, Account.Name, Id from Contact LIMIT 10"; DataTable table = GetSforceData(query, 200); dataGridView1.DataSource = table;
DataTable GetSforceData(string strSQL, int iBatchSize) { DataTable dt = null; SforceService binding = new SforceService(); //get account name, account password and security token here LoginResult lr = binding.login(strAccountName,strAccountPassword + strSecurityToken); if (!lr.passwordExpired) { binding.Url = lr.serverUrl; binding.SessionHeaderValue = new partnerWSDL.SessionHeader(); binding.SessionHeaderValue.sessionId = lr.sessionId; partnerWSDL.QueryResult qr = null; binding.QueryOptionsValue = new partnerWSDL.QueryOptions(); binding.QueryOptionsValue.batchSize = iBatchSize; binding.QueryOptionsValue.batchSizeSpecified = true; try { qr = binding.query(strSQL); } catch (Exception e) { MessageBox.Show(e.ToString(), "Error peforming query"); return null; } bool done = false; if (qr.size > 0) { dt = new DataTable(); partnerWSDL.sObject sOtmp = (partnerWSDL.sObject)qr.records[0]; for (int i = 0; i < sOtmp.Any.Length; i++) { dt.Columns.Add(sOtmp.Any[i].LocalName); } string[] prValues = new string[sOtmp.Any.Length]; while (!done) { for (int i = 0; i < qr.records.Length; i++) { sOtmp = (partnerWSDL.sObject)qr.records[i]; for (int j = 0; j < sOtmp.Any.Length; j++) { if (sOtmp.Any[j].ChildNodes.Count > 1) { prValues.SetValue(sOtmp.Any[j].ChildNodes[2].InnerText, j); } else { prValues.SetValue(sOtmp.Any[j].InnerText, j); } } dt.Rows.Add(prValues); } if (qr.done) { done = true; } else { qr = binding.queryMore(qr.queryLocator); } } } } return dt; }
So the results will only show the Account.Id not the Account.Name.
But it if I remove the Account.Id from the query then it will show the Account.Name.
It seems like it only can handle one __r type of field per query? Is this a limitation of the API?
Thanks,
Chris
You appear to always pick the 2nd child element
All Answers
You appear to always pick the 2nd child element
Thanks, that helped a lot. Here's my updated code in case someone finds it useful. This code is working great: