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
JakesterJakester 

Quick Mass Close Button trouble

Hi All,

I'm hoping to get some help with this guide on how to make a quick close button that works on a list. I just tried to implement this, and I'm getting an error when I click the button:

 "A problem for this on-click javascript button or link was encountered: sforce is not defined"

Any ideas? I confirmed that Closed is indeed a status for the Status picklist and double-checked that I followed the rest of the instructions.

Thanks!

-Jake
Best Answer chosen by Admin (Salesforce Developers) 
werewolfwerewolf

I can read it OK, and I see this:

 

{!GETRECORDIDS( Registered_Pen__c.Id )}

 

That doesn't make any sense.  It should either be:

 

{!GETRECORDIDS( $ObjectType.Registered_Pen__c )}

 

Or if you're trying to delete Cases and not Registered Pens,

 

{!GETRECORDIDS( $ObjectType.Case )} 

All Answers

werewolfwerewolf
Put this at the beginning:

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
JakesterJakester
Brilliant! Thanks so much!
JakesterJakester
Because you are the Super Contributor, any chance you could point me to a way to Mass Delete from a List? The same folks that wanted the ability to Quick Close from a list would love to be able to Quick Delete...
werewolfwerewolf
Strikingly similar to the code you copied from the blog.  Just lose the change to caseUpdate.Status in the for loop, change sforce.connection.update to sforce.connection.delete, and maybe add an "Are you sure?" alert in front of it.
JakesterJakester

Hmmm... are you sure? It's returning an error "sforce.connection.delete is not a function"

Here's my code:

Code:
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}

var records = {!GETRECORDIDS($ObjectType.Case)};
if (records[0] == null)
{
alert("Please select at least one case to delete.")
} else {
//Get more info on the cases that were selected and generate a query out of it
var updateRecords = [];

//Iterate through the returned results
for (var recordIndex=0;recordIndex<records.length;recordIndex++) {
var caseDelete = new sforce.SObject("Case");
caseDelete.Id = records[recordIndex];
updateRecords.push(caseDelete);
}

var result = sforce.connection.delete(updateRecords);

//handle errors here
if (result.error) {
alert('There was an error processing one or more cases');
}

//Reload the list view to show what he now owns
parent.window.location.reload();
}


 

werewolfwerewolf
Sorry, it's different in JS than in most other languages because delete is a keyword.  It's sforce.connection.deleteIds.
JakesterJakester

Ah! Well, that got me a neat new error:

{faultcode:'soapenv:Client', faultstring:'Unexpected element {urn:partner.soap.sforce.com}type during simple type deserialization', }

Same code as previously posted, only I added the "Ids" to the delete function.

werewolfwerewolf
Ah, right.  deleteIds wants just the Ids, not the whole case object.  So instead of:

for (var recordIndex=0;recordIndex<records.length;recordIndex++) {
var caseDelete = new sforce.SObject("Case");
caseDelete.Id = records[recordIndex];
updateRecords.push(caseDelete);
}
Just do this:

for (var recordIndex=0;recordIndex<records.length;recordIndex++) {
updateRecords.push(records[recordIndex]);
}



Message Edited by werewolf on 11-20-2008 05:31 PM
JakesterJakester

You are a scholar and a gentleman!! Thank you so much!!

For the community, here's the complete code for a quick delete case button, courtesy of werewolf:

Code:
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}

var records = {!GETRECORDIDS($ObjectType.Case)};
if (records[0] == null)
{
alert("Please select at least one case to delete.")
} else {
//Get more info on the cases that were selected and generate a query out of it
var updateRecords = [];

//Iterate through the returned results
for (var recordIndex=0;recordIndex<records.length;recordIndex++) 
{updateRecords.push(records[recordIndex]);
}

var result = sforce.connection.deleteIds(updateRecords);

//handle errors here
if (result.error) {
alert('There was an error processing one or more cases');
}

//Reload the list view to show what he now owns
parent.window.location.reload();
}


 

James_AdapxJames_Adapx

 I am having alittle trouble with this delete function. I have added the code to the search page for this custom object so that when the user finds a record in the search they can check the box next to the record(s) and then click the delete_record button I put on the page. The problem is it never brings in any Id's to delete... So im guessing its something in the syntax for the highlighted line but im not sure what it is.

 

 

 

 

{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

var records = {!GETRECORDIDS( Registered_Pen__c.Id )};
if (records[0] == null)
{
alert("Please select at least one case to delete.")
} else {
//Get more info on the cases that were selected and generate a query out of it
var updateRecords = [];

//Iterate through the returned results
for (var recordIndex=0;recordIndex<records.length;recordIndex++)
{updateRecords.push(records[recordIndex]);
}

var result = sforce.connection.deleteIds(updateRecords);

//handle errors here
if (result.error) {
alert('There was an error processing one or more cases');
}

//Reload the list view to show what he now owns
parent.window.location.reload();
}

 

 

Thanks 

JakesterJakester
This will be much easier to read if you repost it using the Code button. If you couldn't find or didn't realize there was a Code button, might I recommend you vote on this idea?
werewolfwerewolf

I can read it OK, and I see this:

 

{!GETRECORDIDS( Registered_Pen__c.Id )}

 

That doesn't make any sense.  It should either be:

 

{!GETRECORDIDS( $ObjectType.Registered_Pen__c )}

 

Or if you're trying to delete Cases and not Registered Pens,

 

{!GETRECORDIDS( $ObjectType.Case )} 

This was selected as the best answer
James_AdapxJames_Adapx

 Thanks, that works..

 

 

{!GETRECORDIDS( $ObjectType.Registered_Pen__c )}

James_AdapxJames_Adapx
Ah, now I see the code button, that is a helpfull tip. Thanks
RachelP27RachelP27

I'm looking for a way to mass close open activities (tasks) from within a ticket.

 

As a secondary want, I would love to be able to mass close tasks from the home tab. Can someone help me out?

Thanks!

werewolfwerewolf

You could conceivably mass close activities using a similar technique -- the problem is that there isn't a single, consolidated Activities view that you can put your custom button on.  At least, I don't think there is.  The My Tasks view is not a real list view, and it has no checkboxes like normal list views do.

 

Your only option is probably to build a Visualforce page that shows these activities in a list with checkboxes and gives users the ability to mass close them.  That is unfortunately much more complicated than the simple Mass Close code.

acl5acl5

I am trying to update some field values using an on-click JS button.  I can get the update to work is I hard code the new values, but using  the methods shown above I can't update a field on the object to equal a different field on the object.

 

I assumed that if I used a query call to get the sObjects I wanted to update I could get it to work, but I am having a tough time getting the query to accept a javascript variable for the IN clause.  I get a "Malformed_Query" faultcode when I push the button.

 

{!REQUIRESCRIPT("/soap/ajax/16.0/connection.js")} var records= {!GETRECORDIDS($ObjectType.SalesOrderLineItem__c)}; var newRecords = []; if (records[0] == null) { alert("Please select at least one row") ; } else { var test = sforce.connection.query( "SELECT Id, Quantity__c, Quantity_Shipped__c From SalesOrderLineItem__c WHERE Id ='{!GETRECORDIDS($ObjectType.SalesOrderLineItem__c)}'"); alert(test); window.location.reload(); }

 

 

Any suggestions?

 

 

acl5acl5

I noticed an error in the code I posted, I've been making a lot changes trying to get something to work.

 

The code should read (This still doesn't work):

{!REQUIRESCRIPT("/soap/ajax/16.0/connection.js")} var records= {!GETRECORDIDS($ObjectType.SalesOrderLineItem__c)}; var newRecords = []; if (records[0] == null) { alert("Please select at least one row") ; } else { var test = sforce.connection.query( "SELECT Id, Quantity__c, Quantity_Shipped__c From SalesOrderLineItem__c WHERE Id IN('{!GETRECORDIDS($ObjectType.SalesOrderLineItem__c)}')"); alert(test); window.location.reload(); }

 

werewolfwerewolf

Very likely the problem is in how you're formatting the query.  Try installing Firebug to debug it, store your query in a string, and put

 

debugger;

 

after you store the query.  Just eyeballing it will probably be enough to show that your IN clause is messed up.

SarifkaSarifka
Hi, Can you share the code for the mass close cases from a view? The link provided doesn't seem to direct to the correct place. Much appreciated! Sara
werewolfwerewolf

The blogs have moved.  It's here now.

werewolfwerewolf

It's kind of hard to see it but the text "It's here now" above is a link to the blog post about it.

SarifkaSarifka
Thanks- that was really helpful!