-3

I am new bie on coldfusion, Please help me to get All ID, Name, Type Using CFLOOP?

enter image description here

<cfset categoryList = application.salesforce.queryObject("SELECT Id, Name FROM Category__c") />
<cfdump var="#categoryList#"> 
<cfloop list="#structKeyList(categoryList)#" index="key"> 
<cfdump var="#categoryList[key]#"> 
</cfloop>

The above Code give me the below result :
true
3
enter image description here

Sameek Mishra
  • 9,174
  • 31
  • 92
  • 118
  • 1
    We are not here to do your work for you. [ask] Have you tried anything yet? If so, show us that code and explain how it is not working for you. Some simple searching of the internet or even reading the online documentation will answer your question. – Miguel-F Aug 07 '13 at 18:18
  • Thanks to give me such a feedback. I got the results value but not able to iterate on the result value. – Sameek Mishra Aug 07 '13 at 18:30
  • Please [edit] your question with the additional information. It is too difficult to read in these comments and might also help get rid of the negative votes you are receiving. – Miguel-F Aug 07 '13 at 18:35
  • Running your queries through an application scope object could lead to thread safety issues. You should avoid user the application scope for things like this. – Dave Ferguson Aug 08 '13 at 17:35
  • @DaveFerguson - Depends on whether the components are stateful or stateless. Typically DAO's are stateless. With stateless components, as long you localize all function local variables, then it is perfectly safe. – Leigh Aug 13 '13 at 19:03

3 Answers3

2

This is a pretty basic question you could have easily found my googling, but here you go anyway.

<cfoutput>
  <cfloop query="queryName">
    #queryName.ID#
    #queryName.name#
    #queryName.type#
  </cfloop>
</cfoutput>

Note you can replace cfloop with cfoutput and remove the cfoutput around everything.

Matt Busche
  • 14,216
  • 5
  • 36
  • 61
  • Thanks For your reply. But i didn't have queryname here. and the queryObject method return the above struct. – Sameek Mishra Aug 07 '13 at 18:26
  • 2
    *Re: i didn't have queryname here* Yes you do. Think about it a minute. The `categoryList` structure contains several keys. One of which represents the query object: `results`. Therefore the query name is `categoryList.results`. – Leigh Aug 07 '13 at 18:57
2

I would just use a "cfoutput" tag...

<cfoutput query="yourquery">
   #yourquery.ID#
   #yourquery.name#
   #yourquery.type#
</cfoutput>
1

Based on the updates that you have made to your question it looks like you might need to do something like this:

<cfoutput>
  <cfloop query="categoryList.results"> 
     <p>#id# - #name# - #type# </p>
  </cfloop>
</cfoutput>

Note that I have not tested this code

Miguel-F
  • 13,450
  • 6
  • 38
  • 63