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
ldtechldtech 

Simple connection to Salesforce as external database

I'm working with a customer that uses salesforce currently and would like to add a few features onto their web site product (that we've developed) that interact with some data that's stored in their salesforce account.

My question is, I'm working with Coldfusion which doesn't appear to have any packages for salesforce so I was wondering if it's possible to do a simple connection with AJAX in order to draw down and update some of their data.  I was reviewing some of the AJAX proxy options and think that this would be the route I would go down, but other than the AJAX Proxy page I can't find any more information on how to get started with this and get it setup.

Some of the problems I'm having is finding a link to a javascript library that they seem to reference when doing their AJAX call connection and finding some basic instruction other than what they've got on that proxy page.  It seems pretty simple once I've got the library and connection instructions (if that's all there is to it) but I'd like to know if there's anything else I need to ramp up on before jumping into this headlong.

I've got about a week to show some decent progress and we'd like to have it up and running (doing updates to salesforce and drawing data down) in about a month.  Is this a reasonable expectation?
jpizzalajpizzala
The AJAX Toolkit Developer's Guide would be a good place to start when learning the basics of the Salesforce AJAX libraries.

Look under Working with the AJAX Toolkit -> Connecting to the API for a URL for the connection library.

HTH


Message Edited by jpizzala on 04-14-2008 10:15 AM
werewolfwerewolf
Based on your description it sounds like you may have it backwards.  If you want to use the Salesforce data within your own web application, the Salesforce proxy won't help you, because it makes the data appear to come from a salesforce.com domain.  If you want everything to happen within your own website, you need to proxy it yourself, since all the data on a page needs to appear to come from yourdomain.com.

It would probably be a lot easier just to connect ColdFusion to the Salesforce web services API.  See this blog post for a start on it:

http://blog.webdh.com/index.cfm/2007/10/11/Using-CF-to-create-a-Lead-in-SalesForce-using-SOAP
ldtechldtech
Wow, that is EXACTLY what I was looking for.  Thanks so much for that link :)
mshelmanmshelman
The approach shown in the blog post is really not optimal for cold fusion as CF can handle wsdl's as readily as Java or .Net. Store a local copy of your wsdl and use the CF creatobject "webservice" tag to instantiate it and then you can call the methods in the wsdl from CF without having to compose the SOAP messages manually. Here's login code to get you started:

    <cffunction name="SFLogin">
        <cfargument name="userName" required="yes" type="string">
        <cfargument name="password" required="yes" type="string">   
        <cfargument name="wsdl" required="yes" type="string">           
        <cfset sfdc = createObject("webservice","#wsdl#") />
        <cfset result = sfdc.login("#ARGUMENTS.userName#","#ARGUMENTS.password#") />
        <!--- 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.getServerURL()) />
       
        <cfset result = sfdc.getUserInfo() />
        <cfreturn sfdc>
    </cffunction>
ldtechldtech
Thanks again, one last question I promise.  Which WSDL should I use?  The partner one or the metadata?
mshelmanmshelman
The obvious disadvantage to using the Enterprise wsdl is that you will need to refresh it whenever there is a change, i.e., whenever a custom field is added. Either wsdl is usable with the above technique.
Kathryn_doanKathryn_doan
I have tried using the "SFLogin" function in my cfc and while invoking the web service, it gives me an error "coldfusion.xml.rpc.ServiceProxy$ServiceInvocationException : Cannot perform web service invocation login.]"
 
I have my enterprise.xml file residing on my local server...
 
This is how I am invoking the web service
 
<cfinvoke webservice="http://myserver/mysite/Salesforce/Salesforce.cfc?wsdl" method="AuthenticateSalesforceLogin" timeout="120" returnVariable="strDetails">
 <cfinvokeargument name="strUsername" value="abc" />
 <cfinvokeargument name="strPassword" value="1234" />
 <cfinvokeargument name="wsdl" value="http://myserver/mysite/Salesforce/enterprise.xml?wsdl" /> 
</cfinvoke>
mshelmanmshelman
I think maybe you're overcomplicating this. Simply call the SFLogin function with the three parameters and it should return an API binding you can then use to make API calls against Salesforce as in sfdc.getUserInfo(). You will probably have to concat a security token to your password. I'm also not sure why this path "http://myserver/mysite/Salesforce/enterprise.xml?wsdl" ends with ?wsdl

mike
Kathryn_doanKathryn_doan

Hi,

I have got the ServiceInvocationException fixed. I concatinated the security token to my password and it worked without any error. I have removed the "?wsdl" from the http://myserver/mysite/Salesforce/enterprise.xml?wsdl file path.

When returning the value from sfdc from the function its returning me coldfusion.xml.rpc.ServiceProxy@1b26f42 as output.

I would just like to get the login success/failure status as my output from the SFLogin function. I am then looking at creating / updatign an object for contact in salesforce.

Can you help me with some sample code for creating / updating a Contact.

Thanks,
Kathryn

mshelmanmshelman
Kathryn

Once you have the binding to Salesforce you can then call all the API methods on it. Use the API documentation for info on the available methods.

So to create a contact you have something like this with Enterprise wsdl:

            aContact = StructNew();
            aContact.type = "Contact";
            aContact name  = "Jon Doe";
            sObjs = arraynew(1);
            sObjs[1] =aContact;
            sfdc.create(sObjs);

If you reply to teracotta@sbcglobal.net I'll send you a CF library that abstracts dealing with salesforce in CF (designed to work with the partner wsdl).

Mike