You need to sign in to do that
Don't have an account?
ldtech
Retrieving simple query results
I've got a relatively simple little setup to test out retrieving some salesforce data. I can't quite get the records to retrieve the data inside them however (like first name, last name, etc.). Here's what I've got:
<cfset queryName = sfObject.query("SELECT firstname FROM contact")>
<cfset queryRecords = queryName.getRecords()>
<cfdump var="#ArrayLen(queryRecords)#">
<cfdump var="#sfObject.describeGlobal().getTypes()#">
As you can see I'm using CF. I was breaking down the objects with cfdump and figuring out what methods were inside each class, but I've come to a stopping point where I can't figure out how to retrieve the exact data I need (such as first name). The query executes correctly (as I tested incorrect ones out to make sure) but using things like:
queryRecords.firstname
or
queryRecords[1].firstname
doesn't work (although the second one appears to be more correct). There should be 21 objects inside of queryRecord so queryRecord[1] should be perfectly fine (per the array length check). Other websites I've checked out have done it just like this, with a loop around what should be the record result set to output all of the results they retrieve.
Thanks in advance :)
<cfset queryName = sfObject.query("SELECT firstname FROM contact")>
<cfset queryRecords = queryName.getRecords()>
<cfdump var="#ArrayLen(queryRecords)#">
<cfdump var="#sfObject.describeGlobal().getTypes()#">
As you can see I'm using CF. I was breaking down the objects with cfdump and figuring out what methods were inside each class, but I've come to a stopping point where I can't figure out how to retrieve the exact data I need (such as first name). The query executes correctly (as I tested incorrect ones out to make sure) but using things like:
queryRecords.firstname
or
queryRecords[1].firstname
doesn't work (although the second one appears to be more correct). There should be 21 objects inside of queryRecord so queryRecord[1] should be perfectly fine (per the array length check). Other websites I've checked out have done it just like this, with a loop around what should be the record result set to output all of the results they retrieve.
Thanks in advance :)
Dim oResult As New sforce.QueryResult
oResult = oProxy.query("SELECT ID, ContactId, CaseNumber, Subject, Status FROM Case")
If Not oResult.records Is Nothing AndAlso oResult.records.Length > 0 Then
Dim oCase As sforce.Case
Dim oTable As New System.Data.DataTable
oTable.Columns.Add("ID")
oTable.Columns.Add("ContactID")
oTable.Columns.Add("CaseNumber")
oTable.Columns.Add("Subject")
oTable.Columns.Add("Status")
oDataSet.Tables.Add(oTable)
For Each oCase In oResult.records
Dim oDataRow As DataRow = oDataSet.Tables(0).NewRow
oDataRow.Item(0) = oCase.Id
oDataRow.Item(1) = oCase.ContactId
oDataRow.Item(2) = oCase.CaseNumber
oDataRow.Item(3) = oCase.Subject
oDataRow.Item(4) = oCase.Status
oDataSet.Tables(0).Rows.Add(oDataRow)
Next
End If
object of com.sforce.soap.partner.sobject.SObject
Class Name com.sforce.soap.partner.sobject.SObject
Methods
Method Return Type
equals(java.lang.Object) boolean
getDeserializer(java.lang.String, java.lang.Class, javax.xml.namespace.QName) org.apache.axis.encoding.Deserializer
getFieldsToNull() java.lang.String[]
getFieldsToNull(int) java.lang.String
getId() java.lang.String
getSerializer(java.lang.String, java.lang.Class, javax.xml.namespace.QName) org.apache.axis.encoding.Serializer
getType() java.lang.String
getTypeDesc() org.apache.axis.description.TypeDesc
get_any() org.apache.axis.message.MessageElement[]
hashCode() int
setFieldsToNull(int, java.lang.String) void
setFieldsToNull(java.lang.String[]) void
setId(java.lang.String) void
setType(java.lang.String) void
set_any(org.apache.axis.message.MessageElement[]) void
P.S. That appears to be VB, I'm hopefully looking for CF solution but I can understand both if it applies to CF :)
Message Edited by ldtech on 04-17-2008 11:34 AM
not sure the syntax in CF, but loop thru the resultset and cast the result as a contact:
something like:
for each oContact as sforce.contact in [your_query_result_set]
once it is cast, you can access the fields of each record like this:
[your_variable_name] = oContact.FirstName
etc
and joined resultsets might look like:
oContact.LastModifiedBy.Name or
oContact.CreatedBy.DateCreated
etc
Message Edited by ldtech on 04-17-2008 12:40 PM
What are the possibilities of the SalesForce dev team writing up a small custom Java class to incorporate it with ColdFusion? It wouldn't be a huge leap to just take some of the Java code you guys already use and put it over there would it? I'm sure it would solve other people's problem incorporating CF and SalesForce together without the need to write their own Java classes just to get it integrated.
Also as some constructive criticism, I found the 'wiki' hard to find my way around in general. The pages were laid out in huge lists with very little differentiation between areas, and the tutorials were very inconsistant in quality. One of the lower rated ones would be the presentation where someone builds a small sample app in a video taped demonstration but it's done ENTIRELY OFFSCREEN. There's a LOT of material that repeats itself and the API guides written up in very nice AJAX programs are needlessly split up. There's only a handful of information in each for some reason. Lastly, maybe I'm just spoiled for Java docs, but I think it would be helpful if the actual method calls for the base Salesforce setup were available somewhere and the object heirarchy so someone working in a "lesser" language like myself could easily tell what calls what instead of having to dump each individual object to find out what calls I need to make in order to access the info I want.
Overall, looks like a promising bit of development you have going on ;)
Message Edited by ldtech on 04-18-2008 09:30 AM
so anyway referring to your dump of sobject above getAny returns an array of fields (axis MessageElement objects) which in turn have getName and getValue methods. getId returns the id of the sobject and getType would tell you the type of sobject that you're dealing with