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
vspvsp 

delete not working within S-Control

Hi,

I am using an S-Control from which I am able to invoke query, create, update, etc, but I am unable to use delete. As soon as I put the delete method in the S-Control, it stops processing any Javascript.

I have declared:
<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
and I do sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}");

With this I am able to do:
- sforceClient.query("query string")
- sforceClient.create(arr)
- sforceClient.update(arr)
I have declated var arr=new Array(), and added multiple Sforce.DynaBean objects into it and passed it.

But with delete, I am not able to pass in an array declared like this, or even use as per the example provided in S-Control documentation (sforceClient.delete([id])).

Please help!

Thanks,
VSP.
SteveBowerSteveBower

Are you saving the result?

var x = sforceClient.delete... .etc.

If so, what's in x?

Are you using a try/catch block?

try {
    x = sforceClient.delete(id);
    alert(x);
} catch(e) {
    alert("Exception: " + e);
}

Otherwise, we can't be much help unless you post whole code sections.

Good luck, Steve.


vspvsp
Hi Steve,

It doesn't even get to the point where execution happens. I have some initialization Javascript onLoad of the page, and delete is expected to happen onClick of a button. But as soon as I put in the function for delete, even the onLoad scripts stop working so the logic is not getting to the point where delete is called.

The code is simple. I have:
var ids = new Array();
I keep adding the required ids to this. And then do:
sforceClient.delete(ids);

As soon as I put in this above delete statement, onLoad scipts stop working as well! And if I remove that one line, scripts work fine (except of course, for the deletion).

Do you have any idea why this happens?

Thanks,
Vima.
gsickalgsickal

try deleting a single record using _delete as follows:

var ids = new Array(1);
ids[0] = "someid";
var csr = sforceClient._delete([ids]);

if (csr[0].success == false) {
    alert("Error deleting object " + csr[0].id + "\n" + csr[0].errors[0].message);
}

SteveBowerSteveBower

Perhaps we're all idiots... :-)


the prototype is: 

Sforce.Client.prototype.Delete = Sforce.Client.prototype._delete;


Try capitalizing your "delete" and see what happens.  Steve.
DevAngelDevAngel
Right, I think we are :smileytongue:

I forgot that lowercase delete is reserved and can't be used in a prototype so I made it underscore delete with an alternate proper case delete.  Crap, I can't believe I forgot about that.

Ah, to be a mere human...

Cheers
vspvsp
Thanks everybody, it worked when I replaced delete with Delete. I had never bothered to try it, because update, create, query, etc were in lower-case! Didnt think it was that simple. :)

Cheers!
VSP.