function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CFMX_DEVCFMX_DEV 

ColdFusion MX Sample Code?

Does anyone have some ColdFusion MX sample code for integration with SF APIs?

Specifically for  API Version 2.5: Initial login, setting session headers and subsequent data updates.

I've seen several postings related to this topic but no conclusion was ever presented.

Much appreciated!

 

eyewelleyewell

Here is some sample code that sets up webservices, adds session ID to the SOAP headers, and performs a sample query.

 

 

<cfoutput>
<cfset sfdc = createObject("webservice","#sforceURL#") />
 
<!--- Developer Login --->
<cfset result = sfdc.login("me@domain.com","#password#") />
 
<p>session id = #result.getSessionId()#</p>
<p>server URL = #result.getServerURL()#</p>
 
<!--- create a SOAPHeaderElement called SessionHeader in the SforceService
namespace: --->
<cfset authHeader =
createObject("java","org.apache.axis.message.SOAPHeaderElement")
 .init("SforceService", "SessionHeader") />
<!--- add (and populate) a text node called sessionId: --->
<cfset
authHeader.addChildElement("sessionId").addTextNode(result.getSessionId())
/>
<!--- set the entire soap header: --->
<cfset sfdc.setHeader(authHeader) />
<!--- change the endpoint URL to what was returned by the login method: --->
<cfset
sfdc._setProperty("javax.xml.rpc.service.endpoint.address",result.getServerU
RL()) />
<cfset result = sfdc.getUserInfo() />
 
<p>
 User's Organization = <strong>#result.getOrganizationName()#</strong><br>
 User's E-mail: <strong>#result.getUserEmail()#</strong><br>
 User's UserID: <strong>#result.getUserId()#</strong><br>
 User's Full Name: <strong>#result.getUserFullName()#</strong></P>
 
<cfset objects = sfdc.describeGlobal() />
<cfset nTypes = arrayLen(objects.types) />
 
<p>Types that can be queried:<cfloop index="i" from="1" to="#nTypes#">
#objects.types[i]#</cfloop></p>
 
<cfset result = sfdc.query("select FirstName, LastName from Contact") />
<cfset nRecords = arrayLen(result.records) />
<p>Contact records:<cfloop index="i" from="1" to="#nRecords#">     <br
/>#result.records[i].firstName# #result.records[i].lastName#</cfloop></p>
 
</cfoutput>

 

Message Edited by eyewell on 06-15-2004 03:06 PM