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

AJAX Toolkit - Re-entrant behavior

I'm loving the new AJAX toolkit! However, I am running into an issue with the following code excerpt. I am looping through currentReps (which is queryResult.records array). For each record, I create a new DynaBean and set some data. The call to getUserQuota does another sforceClient.Query(...) and returns the first record returned.

When getUserQuota() returns, it looks like my estimateSplit (which should be of type Estimate_Split__C) DynaBean has been magically transformed into type User_Quota__c.

Is there a limitation on writing re-entrant code with the library? If so, is there a way to get around this?


Todd Breiholz
Meredith Corporation

function convertToEstimateSplits(currentReps) {
var estimateSplits = new Array(currentReps.length);
var i;
for (i = 0; i < currentReps.length; i++) {
var estimateSplit = new DynaBean("Estimate_Split__c");
var advSplit = currentReps[i];
estimateSplit.set("estimate_net_net_revenue__c", opportunityNetNetRevenue);
estimateSplit.set("ownerid", advSplit.salesrep__c);
estimateSplit.set("pub_issue__c", campaignId);
estimateSplit.set("estimate_split__c", advSplit.advsrep_accnt_prcnt__c);
var quota = getUserQuota(estimateSplit.ownerid);
if (quota != null) {
estimateSplit.set("split_rep_fiscal_quota__c", quota.quota_amount__c);
estimateSplit.set("estimate_quota_fy__c", quota.quota_fy__c);
estimateSplits[i] = estimateSplit;
return estimateSplits;
function getUserQuota(userId) {
var fiscal = accountingPeriodToFiscal();
var userQuotaResult = sforceClient.Query("select Quota_Amount__c, Quota_FY__c from User_Quota__c where Quota_FY__c = '" +
fiscal +
"' and User__c = '" +
userId +
return userQuotaResult.records[0];

Hi talanb,

Interesting behavior, I'll take a look and see what might be going on here.


I can reproduce the behavior you have described and will work on a fix.


Thanks for the great catch!


Hi talanb,

I'm glad you caught that.  This issue had to do with the declaration of the properties variable for a dynabean object that the way those properties where be referenced (this, var and implicit variable declaration inside a javascript object has a big impact on their visibility).  The way the properties where be accessed and declared caused them to behave as if declared statically.

This means that the properties of the last DynaBean created would be used for sets and gets as evidenced when executing the toString() method.  Anyway, I'm going to submit a patch to hopefully get pushed to the website this afternoon (PST).

In the mean time, you can point sforceclient.js to



Thanks for your quick response. The changes you made seem to behaving much better. However, I now am seeing problems with the sObjects element during a Create. The version you pointed me to this morning generates the following:

<sObjects xmlns:ns3=\"\">
<type xmlns=\"\">Estimate_Split__c</type>

Is it possible that the Property.toSoap method should be referencing _name instead of this._name?


Todd Breiholz
Meredith Corporation

Hi Todd,

Yes, I have posted a fix on  I've also submitted a ticket to have the dynalib.js file which is the one that handle SObjects or DynaBeans to be updated at the next web update.

Sorry for the errors (be nice once this is out of beta and stable).