1

I am using mass delete list button.I am using following code for mass delete:

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
var selectedRecords = {!GETRECORDIDS( $ObjectType.Case)}; 
sforce.connection.deleteIds(selectedRecords); 
navigateToUrl(window.location.href);

I am able to delete cases irrespective of record type. But can anyone tell me how can I do this for a specific record type?

0

If you want to do this for a specific record type, you'd have to retrieve the records first:

{!RequireScript("/soap/ajax/39.0/connection.js")}
var recordIds = {!GetRecordIds($ObjectType.Case)};
var records = sforce.connection.retrieve("Id,RecordType.Name", "Case", recordIds);
recordIds = [];
records.forEach(function(value) {
  if(value.RecordType && value.RecordType.Name === "Some Record Type") {
    recordIds.push(value.Id);
  }
});
sforce.connection.deleteIds(recordIds);
window.location.reload();
| improve this answer | |
  • {!RequireScript("/soap/ajax/39.0/connection.js")} var recordIds = {!GetRecordIds($ObjectType.Case)}; var records = sforce.connection.retrieve("Id,RecordType.Name", "Case", recordIds); recordIds = []; records.forEach(function(value) { if(value.RecordType.Name === "AdOpsTech") { recordIds.push(value.Id); } }); sforce.connection.deleteIds(recordIds); window.location.reload(); – Gmi May 30 '17 at 4:28
  • when i tried the above code snippet for "AdOpsTech" record type i am getting the below errors..."Errors: • Enter a URL that is valid and well-formed • Function REQUIRESCRIPT may not be used in this type of formula"Please let me know what changes are to be done this.. Thanks in Advance !! – Gmi May 30 '17 at 4:30
  • @Gmi you need to use the onclick behavior instead of URL. – sfdcfox May 30 '17 at 5:12
  • @sfdcfox...i am not getting where can i use Onclick instead of URL.Could you please help me the change in code snippet. Thanks.. – Gmi May 30 '17 at 5:53
  • @Gmi in the Behavior dropdown when creating the button, one choice should be OnClick JavaScript. – sfdcfox May 30 '17 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.