You need to sign in to do that
Don't have an account?
CaptaConsulting
AJAX sforceclient.js beta
Hi,
i am trying to adds leads to a campaign with the AJAX toolkit beta1 and the CampaignMember object, but it fails.
A snippet of code:
..........
sforceClient.setBatchSize(10);
_qrLeads = sforceClient.Query("Select Id, LastName, FirstName, State From Lead where State = '"+provincia+"'");
if (_qrLeads.size > 0) {
for (var i=0;i var lead = _qrLeads.records[i];
var campMember = new DynaBean("CampaignMember");
campMember.set("CampaignId","{!Campaign_ID}");
campMember.set("LeadId",lead.id);
campMember.set("Status","Sent");
var saveResult = sforceClient.Create(campMember)[0];
}
}
.......
Any Help??
Thanks.
Victor Alvarez Fuente
i am trying to adds leads to a campaign with the AJAX toolkit beta1 and the CampaignMember object, but it fails.
A snippet of code:
..........
sforceClient.setBatchSize(10);
_qrLeads = sforceClient.Query("Select Id, LastName, FirstName, State From Lead where State = '"+provincia+"'");
if (_qrLeads.size > 0) {
for (var i=0;i var lead = _qrLeads.records[i];
var campMember = new DynaBean("CampaignMember");
campMember.set("CampaignId","{!Campaign_ID}");
campMember.set("LeadId",lead.id);
campMember.set("Status","Sent");
var saveResult = sforceClient.Create(campMember)[0];
}
}
.......
Any Help??
Thanks.
Victor Alvarez Fuente
Hi,
I am going to explain the test more.
------------
I have created a campaign manually in salesforce.com
The campaign is "Active" and with no Leads or Contacts.
------------
Now i want to add some Leads via the AJAX Toolkit to this campaign.
But when i click in the Custom Link, i don´t have any execution errors but when i reloaded the campaign page there´s no Leads associated to the campaign.
If i add some new javascript lines with alerts to inspect the "saveResult" value,
..........
sforceClient.setBatchSize(10);
_qrLeads = sforceClient.Query("Select Id, LastName, FirstName, State From Lead where State = '"+provincia+"'");
if (_qrLeads.size > 0) {
for (var i=0;i<_qrLeads.records.length;i++) {
var lead = _qrLeads.records[i];
var campMember = new DynaBean("CampaignMember");
campMember.set("CampaignId","{!Campaign_ID}");
campMember.set("LeadId",lead.id);
campMember.set("Status","Sent");
var saveResult = sforceClient.Create(campMember)[0];
if (saveResult == null) alert("ERROR") //NEW LINE ADDED
else alert(saveResult); //NEW LINE ADDED
}
}
The return alert is always "ERROR", "ERROR", "ERROR", ...........
Thanks.
Victor Alvarez Fuente
Did you ever get this resolved? I'm trying to insert one row with
var saveResult = sforceClient.Create(newCase, createResult(), true);
my alerts keep telling me that it's "undefined"
Not sure if this is related to your issues, but would love to know if you encountered this, or if you get your own issue resolved. thanks!
- I find its best to develop the scontrol locally as a HTML file (logging in via the AJAX toolkit) rather than as a "live" scontrol - easier to edit/update the code that way
- If you use firefox, there is a great & free javascript debugger available here - http://extensionroom.mozdev.org/more-info/venkman
Adam
Hi sommerscm,
The problem with your code is the call back. It needs to just be the name of the function.
var saveResult = sforceClient.Create(newCase, createResult, true); NO PARAMS on createResult.
Hi CaptConsulting,
Looks like it should be ok. Try this code. This does error handling and will also give you the results of the Create call (which you should batch as demonstrated here).
ÂAlso, it is worth mentioning that error handling is done a little differently in the AJAX toolkit than elsewhere. Every call will return an object if the web service is contacted and responds. The object that is returned is either what you would expect assuming there are no data errors (an array of SaveResults, a QueryResult, a SetPasswordResult etc). If the server returns a fault, which is different from a javascript error, the object returned will be a SoapFault object. This means that you should always check the type of the object returned.
There are two ways to do this.
First, each object contains a getClassName() method that will return the name of the object.
var r = sforceClient.MethodCall(p1, p2);
if (r.getClassName() == "MethodCallResult") { alert("got what I thought I should."); }
else { alert("Got a soap fault");}
The second way is to use dltypeof. This is appropriate for the calls that return arrays of objects like the Create call. Because a SoapFault object is not an array you could do this:
var r = sforceClient.Create([lead]);
if (dltypeof(r) != "array") { alert("got what I thought I should."); }
else {alert("Got a soap fault.");}
For the saveResult objects returned from the create, update and delete calls you should always inspect each element for the success flag to determine if the operation was successful. Doing this gives you the ability to also determine the cause for failure by inspecting the errors collection which contains any information about why the service was unable to successfully complete the request.
One other thing to note. Most if not all the Toolkit objects have a toString() method. This is useful in the SoapFault instance because you can let the user know what the problem is by
var r = sforceClient.Create([lead]);
if (dltypeof(r) != "array") { alert("got what I thought I should."); }
else {alert("Got a soap fault.\nThe error was: " + r.toString());}
More documentation and examples will be coming in the next few weeks.
Cheers
to set up a page to work "localy" is basicaly getting the login done without coming from an scontrol, so you would need to pop a login box ( or hard code a login / passwd) , process the login , then jump into your "normal" code.
here is an example, not tested:
function initPage() {
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_60}");
//Check to see if we are standalone (local) or hosted in scontrol
if (sforceClient.getSessionId().indexOf("API_Session_ID") != -1) {
// do a local login
// sforceClient.login ( ... );
}
//Continue with our initialization
pageSetup();
so if you are "local" then you would fall into the if statement, do a login, then continue with the whole thing running outside salesforce. very handy for debugging.
this was taken from the helloworld2.htm example in the ajax toolkit beta download
Message Edited by Ron Hess on 09-20-2005 10:12 AM