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
virago81virago81 

Dynabean.save() returns nothing

All,
I've tried everything but Dynabean.save doesn't return anything.  I've tried sforceClient.create and it returns zip too.

I know that "set" and "create" calls are being made because the API complains if there is an invalid field on "sets" and the callback fires when I use "create" (I've tried both .save() and create() but neither works or returns anything in the saveResult.)

Here are the relevant code snippets.  Any help appreciated.

<script language="javascript" src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js?browser=true"
            type="text/javascript"></script>
...

sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}");
sforceClient.registerInitCallback(getOpportunity);

...

var renewalOppty = new Sforce.Dynabean("opportunity");
    try
    {
        renewalOppty.set("Name", document.OpptyForm.OpptyName.value);
        //renewalOppty.set("Description", document.OpptyForm.OpptyDesc.value);
        renewalOppty.set("Description", "My Description");
       renewalOppty.set("Type",document.OpptyForm.OpptyType.value);
       renewalOppty.set("Amount", m_amount);
       renewalOppty.set("LeadSource", m_leadSource);
       renewalOppty.set("OwnerId", m_ownerId);
       
       var oCloseDate = new Date("12/31/2006");
       renewalOppty.set("CloseDate", oCloseDate);
       renewalOppty.set("StageName", m_stageName);
       renewalOppty.set("ForecastCategory", "Pipeline");
       renewalOppty.set("CurrencyIsoCode", "USD - U.S. Dollar");
       //renewalOppty.set("Country", "US");
       
       //var opptyArray = new Array();
       //opptyArray[0] = renewalOppty;
       saveResult = renewalOppty.save();
       alert(typeof saveResult);
        //sResult = sforceClient.create(opptyArray,dummy);
Ron HessRon Hess
here is the code:
Sforce.Dynabean.prototype.save = function() {
 if (this.fromServer == true || this.containsItem("id") == true) {
  var sr = sforceClient.Update([this])[0];
 } else {
  var sr = sforceClient.Create([this])[0];
 }
 return sr;
};
as you can see it is returning the first element of the Create() array, which may be empty in the case of a fault Try instead, calling this method, bean.mysave();
Sforce.Dynabean.prototype.mysave = function() {
 if (this.fromServer == true || this.containsItem("id") == true) {
  var sr = sforceClient.Update([this]);
 } else {
  var sr = sforceClient.Create([this]);
 }
 return sr;
};

then look at the returned object
virago81virago81
Ron,
Thanks for the reply. Adding the mysave prototype does the job.

Just a note though. There is a serious bug in the API. If there is a problem a currency field (for instance if I try to set a currency and the API doesn't recognize it as a double, then the SaveResult just bombs. It comes back as undefined.

Here is the relevant corrected code for anyone who is interested:
...

ArmanArman
I've noticed that if the server returns an exception for a bad save (say if an email field contained some garbage string) then the save method returns nothing.

I haven't tested this, but possibly sforceclient.update() function could be used as a work around.
ArmanArman
I've noticed that if the server returns an exception for a bad save (say if an email field contained some garbage string) then the save method returns nothing.

I haven't tested this, but possibly update() function could be used as a work around.