From: paragshah on
Hi,

I have a requirement of integrating a coldfusion site to Salesforce CRM
application. I have got salesforce objects in coldfusion (.cfc) through which I
am trying to insert contact details in to Salesforce CRM application.

The components work in the following manner

1. Authenticate the user login in to the Salesforce CRM application by passing
username / password
2. Insert a Contact by passing contact fields and values passed in to the
Contact object

I have attached 3 code files (.cfc) which has the functions to talk to the
Salesforce CRM application
a. sforce.cfc
b. sfobject.cfc
c. generic.cfc

Firstly I am instantiating an object to sforce.cfc file and calling the Login
function passing the username and password (password + security token)

************************************
<cfobject type="component" name="sfdc" component="sforce">
<cfset sfdc.login("abc(a)test.com","xxxxxxxxxxxxxx")>
<cfset binding = sfdc.getBinding()>
************************************

Next I am calling the getSfObject function to pass the Salesforce Object type
i.e. Contact in this case.

************************************
<cfset aContact = sfdc.getSfObject("Contact")>
************************************

Next I am setting the field values for Contact object using the addField
function

************************************
<cfset aContact.addField("FirstName","John")>
<cfset aContact.addField("LastName","Banks")>
<cfset aContact.addField("Account","XYZ Company Limited")>
<cfset aContact.addField("MailingStreet","169 New Lakeshore Road")>
<cfset aContact.addField("MailingCity","Port Dover")>
<cfset aContact.addField("MailingState","Ontario")>
<cfset aContact.addField("MailingCountry","Canada")>
<cfset aContact.addField("MailingPostalCode","N0A 1N3")>
<cfset aContact.addField("Phone","905-555-5555")>
<cfset aContact.addField("Fax","905-555-4545")>
<cfset aContact.addField("Gender__c","Male")>
<cfset aContact.addField("Email","John.banks(a)venturelabour.com")>
<cfset aContact.addField("Title","Senior Executive")>
************************************

Then I am instantiating an object to sfobject.cfc file which contains the
create function to actually add the contact record to Salesforce CRM
application.

************************************
<cfobject type="component" name="sfobj" component="sfobject">
<cfset sfobj.create()>
************************************

While calling the create function I am getting the following error

[b]The create method was not found.[/b]

[i]Either there are no methods with the specified method name and argument
types, or the create method is overloaded with argument types that ColdFusion
cannot decipher reliably. ColdFusion found 0 methods that matched the provided
arguments. If this is a Java object and you verified that the method exists,
you may need to use the javacast function to reduce ambiguity.[/i]

Can someone help me out in fixing this issue?

Thanks
Parag

<!--- sforce.cfc --->

<!--- Generated by Dreamweaver 8 8.0.0.2734 [en] (Win32) - Mon Mar 05 2007
15:08:01 GMT-0800 (Pacific Standard Time) --->

<cfcomponent displayName="Salesforce Wrapper" extends="generic">

<cfparam name="THIS.binding" default="">

<cfscript>
function getFieldNames (soql) {
fromPos = findnocase("from",soql);
fieldStr = trim(mid(soql,7,fromPos - 8));
flds = listtoarray(fieldStr,",");
fldNames = arraynew(1);
for(i=1;i lte arraylen(flds);i=i+1) {
if (find(".",flds[i]) NEQ 0) {
arr = listtoarray(flds[i],".");
ArrayAppend(fldNames,arr[2]);
}
else {
ArrayAppend(fldNames,flds[i]);
}
}
return fldNames;
//String[] fieldNames = fieldStr.split(",");
}
</cfscript>

<cffunction name="getSfObject" access="public" hint="Returns a salesforce
object which can be used for inserting or updating">
<cfargument name="sfType" required="yes" type="string" hint="Name of the
salesforce object, e.g., Lead or Contact">
<cfobject component="sfobject" name="theObj">
<cfset theObj.setBinding(THIS.binding)>
<cfset theObj.setType(ARGUMENTS.sfType)>
<cfreturn theObj>
</cffunction>

<cffunction name="getQueryFromRetrieve" output="false" returntype="query" >
<cfargument name="fldlist" type="string" required="yes">
<cfargument name="objectname" type="string" required="yes">
<cfargument name="ids" type="array" required="yes">
<cftry>
<cfscript>
fldstr = "";
typstr = "";
bFirst = true;
flds = listtoarray(ARGUMENTS.fldlist,",");
// writeoutput("len= " & arraylen(recs));
// flds = recs[1].get_any();
sobjs =
THIS.binding.retrieve(ARGUMENTS.fldlist,ARGUMENTS.objectname,ARGUMENTS.ids);

for (i=1;i lte arraylen(flds);i=i+1) {
if (bFirst) {
fldstr = fldstr & flds[i];
typstr = typstr & "CF_SQL_VARCHAR";
bFirst = false;
}
else {
fldstr = fldstr & "," & flds[i];
typstr = typstr & ",CF_SQL_VARCHAR";
}
}
//fldstr = fldstr & ",id";
//typstr = typstr & ",CF_SQL_VARCHAR";
//writeoutput("i= " & fldstr);
theQuery = queryNew(fldstr,typstr);

if (arraylen(sobjs) GT 0) {
//recs = qr.getRecords();
for (i=1;i lte arraylen(sobjs);i=i+1) {
// writeoutput("i= " & i);
queryaddrow(theQuery, 1);
flds = sobjs[i].get_any();
for (j=1;j lte arraylen(flds);j=j+1) {
querysetcell(theQuery, flds[j].getName(), flds[j].getValue(), i);
}
//querysetcell(theQuery, "id", recs[i].getId(), i);
}
}
return theQuery;
</cfscript>
<cfcatch type="com.sforce.soap.partner.fault.ApiFault">
<cfthrow message="error">
</cfcatch>
</cftry>
</cffunction>

<cffunction name="getQueryFromSOQL" output="false" returntype="query"
hint="Does not support SFDC relationship queries in output -- however you can
use relationships in where clause e.g. 'where account.name<>null'. Also
supports order by clause">
<cfargument name="soql" type="string" required="yes">
<cftry>
<cfscript>
fldstr = "";
typstr = "";
bFirst = true;
flds = getFieldNames(soql);

// writeoutput("len= " & arraylen(recs));
// flds = recs[1].get_any();
qr = THIS.binding.query(ARGUMENTS.soql);

for (i=1;i lte arraylen(flds);i=i+1) {
if (bFirst) {
fldstr = fldstr & flds[i];
typstr = typstr & "CF_SQL_VARCHAR";
bFirst = false;
}
else {
fldstr = fldstr & "," & flds[i];
typstr = typstr & ",CF_SQL_VARCHAR";
}
}
fldstr = fldstr & ",id";
typstr = typstr & ",CF_SQL_VARCHAR";
//writeoutput("i= " & fldstr);
theQuery = queryNew(fldstr,typstr);

if (qr.getSize() GT 0) {
recs = qr.getRecords();
for (i=1;i lte arraylen(recs);i=i+1) {
// writeoutput("i= " & i);
queryaddrow(theQuery, 1);
flds = recs[i].get_any();
for (j=1;j lte arraylen(flds);j=j+1) {
querysetcell(theQuery, flds[j].getName(), flds[j].getValue(), i);
}
querysetcell(theQuery, "id", recs[i].getId(), i);
}
}
return theQuery;
</cfscript>
<cfcatch type="com.sforce.soap.partner.fault.ApiFault">
<cfthrow message="error">
</cfcatch>
</cftry>
</cffunction>


<cffunction name="login" returntype="void" output="false" hint="Initializes
the SF connection -- must be called before other methods">
<cfargument name="userName" required="yes" type="string">
<cfargument name="password" required="yes" type="string">
<cfset THIS.binding =
SFLogin(ARGUMENTS.userName,ARGUMENTS.password,"http://test_server/salesforce/par
tner.xml")/>
</cffunction>

<cffunction name="getBinding" hint="Returns actual SF connection --
SoapBindingStub">
<cfreturn THIS.binding>
</cffunction>

<cffunction name="getPicklistValues" returntype="array" hint="Returns array of
structs with labels and values">
<cfargument name="sobject" type="string">
<cfargument name="sfield" type="string">
<cftry>
<cfset objects = ArrayNew(1)>
<cfset objects[1] = ARGUMENTS.sobject>
<cfset res = THIS.binding.describeSObjects(objects)>
<cfset flds = res[1].getFields()>
<cfloop index="i" from="1" to="#arrayLen(flds)#">
<cfoutput>#flds[i].getName()# #flds[i].gettype()#<br></cfoutput>
<cfif ucase(flds[i].getName()) EQ ucase(ARGUMENTS.sfield)>
<cfoutput>#flds[i].gettype()#</cfoutput>
<cfif flds[i].gettype() NEQ "picklist">
<cfthrow message="Field is not a picklist">
</cfif>
<cfset lst = flds[i].getPicklistValues()>
<cfset vals = ArrayNew(1)>
<cfloop index="j" from="1" to="#arrayLen(lst)#">
<cfset s = structnew()>
<cfset s.value = lst[j].getValue()>
<cfset s.label = lst[j].getLabel()>
<cfset vals[j] = s>
</cfloop>
</cfif>

</cfloop>
<cfreturn vals>
<cfcatch type="com.sforce.soap.partner.fault.ApiFault">
<cfthrow message="error">
</cfcatch>
</cftry>
</cffunction>

<cffunction name="setPassword" access="public" returntype="string"
hint="Wrapper for SF setpassword function">
<cfargument name="userId" required="yes" type="string">
<cfargument name="newPassword" required="yes" type="string">
<!---
this email would be a nice feature but unfortunately it doesnt seem to work
<cfargument name="setEmailHeader" default="false" type="boolean">
<cfif ARGUMENTS.setEmailHeader EQ true>
<cfset emh = createobject("java","com.sforce.soap.partner.EmailHeader")>
<cfset emh.setTriggerUserEmail(javacast("boolean","true"))>
<cfset emh.setTriggerAutoResponseEmail(javacast("boolean","true"))>
<cfset emh.setTriggerOtherEmail(javacast("boolean","true"))>
<cfset
THIS.binding.setHeader("urn:partner.soap.sforce.com","EmailHeader",emh)>
</cfif>--->
<cfset res = THIS.binding.setPassword(ARGUMENTS.userId,ARGUMENTS.newPassword)>
<cfreturn res>
</cffunction>

<cffunction name="newMessageElement" access="public">
<cfargument name="name" required="yes">
<cfargument name="val" required="yes">

<cfobject type="Java" action="Create"
class="org
From: BKBK on
[i]THIS.binding.create(objs);[/i]

You're attempting to pass a parameter to a function that has no arguments.