+ Start a Discussion
Shirley Lafuente 6Shirley Lafuente 6 

Button that would allow you to delete multiple line items on a quote.

I posted once but didn't receive any response.  Has someone developed a button we can place on the quote object that would allow you to "delete" multiple line items all at once?
Best Answer chosen by Shirley Lafuente 6
RbnRbn
Hi Shirley ,

Please follow the below steps and it would resolve your question.

Give this a shot:
Go to Setup | Customize | Quote | Quote Line Items | Buttons & Links
Click on New Button or Link
Name it as: DeleteRecords
Display Type: List Button also check the option: Display Checkboxes (for Multi-Record Selection)
Behaviour: Execute JavaScript
Content Source: OnClick JavaScript
Copy The below Code:
 
{!REQUIRESCRIPT('/soap/ajax/29.0/connection.js')}
try
{
  var selectedRecords = {!GETRECORDIDS( $ObjectType.QuoteLineItem )};
  if(selectedRecords.length < 1)
    alert('Please Select at Least One Row !');
  else
  {
    userConsent = confirm(selectedRecords.length + ' Record(s) will be Deleted. Continue ? ');
    if(userConsent == true)
    {
      delResult = sforce.connection.deleteIds(selectedRecords);
      
      var message = '';
      var msgFailedReason = '<br/><h3>Failed Record(s)</h3><br/><div style="height: 300px;overflow-y: scroll;"><table style="border-collapse: collapse;">';
      var passCount = 0, failCount = 0;
      for(var i=0; i < delResult.length; i++){
        if(delResult[i].getBoolean('success')){
          passCount++;
        }
        else{
          failCount++;
          msgFailedReason += '<tr><td style="vertical-align: top; border-bottom: 1px solid gray;">' + delResult[i].errors.message + '</td></tr>';
        }
      }
      msgFailedReason += '</table></div>';
      
      message = 
        '<b>Record(s) Submitted</b> : ' + selectedRecords.length + '<br/>' + 
        '<b>Record(s) Deleted</b> : ' + passCount + '<br/>' +
        '<b>Failed Record(s)</b> : ' + failCount + '<br/>';

      if(failCount > 0)
        message += msgFailedReason;

      message += '<p align="center"><button class="btn" onclick="window.parent.resultWnd.hide(); window.parent.location.reload(); return false;">Close</button></p>';

      var resultWnd = new SimpleDialog("Mass-Delete-QL-" + Dialogs.getNextId(), false);
      resultWnd.setTitle("Status - Mass Delete Quote Line Items");
      resultWnd.createDialog();
      window.parent.resultWnd = resultWnd;
      resultWnd.setContentInnerHTML(message);
      resultWnd.show();
    }
  }
}
catch(e)
{
  alert('The Action Could not be Completed. Error Message: ' + e);
}

Save it
You now will have to add it to the Quote Line Items Related List.
Navigate to - Quote record - edit Layout - Add button on to the Quote Line Items Related List by clicking the Wedge icon on the Related List.

Rgrds,
Rabi
 

All Answers

Yury BondarauYury Bondarau
Hi Shirley,

There is quite good explanation (with js example) of how to create custom button for mass delete. Please check the following link and get back in case you heave any problems with this button:

https://help.salesforce.com/HTViewHelpDoc?id=links_useful_custom_buttons_mass_delete.htm
Shirley Lafuente 6Shirley Lafuente 6
Thanks Yury.  I'm guessing since this is sample code it might need to be edited.  I followed the instructions but it's giving me a message:  Must select at least one record.  Also, I'm wondering if this code is specific to "Events & Tasks".  I am trying to delete multiple line items on a quote.

Any thoughts?
RbnRbn
Hi Shirley ,

Please follow the below steps and it would resolve your question.

Give this a shot:
Go to Setup | Customize | Quote | Quote Line Items | Buttons & Links
Click on New Button or Link
Name it as: DeleteRecords
Display Type: List Button also check the option: Display Checkboxes (for Multi-Record Selection)
Behaviour: Execute JavaScript
Content Source: OnClick JavaScript
Copy The below Code:
 
{!REQUIRESCRIPT('/soap/ajax/29.0/connection.js')}
try
{
  var selectedRecords = {!GETRECORDIDS( $ObjectType.QuoteLineItem )};
  if(selectedRecords.length < 1)
    alert('Please Select at Least One Row !');
  else
  {
    userConsent = confirm(selectedRecords.length + ' Record(s) will be Deleted. Continue ? ');
    if(userConsent == true)
    {
      delResult = sforce.connection.deleteIds(selectedRecords);
      
      var message = '';
      var msgFailedReason = '<br/><h3>Failed Record(s)</h3><br/><div style="height: 300px;overflow-y: scroll;"><table style="border-collapse: collapse;">';
      var passCount = 0, failCount = 0;
      for(var i=0; i < delResult.length; i++){
        if(delResult[i].getBoolean('success')){
          passCount++;
        }
        else{
          failCount++;
          msgFailedReason += '<tr><td style="vertical-align: top; border-bottom: 1px solid gray;">' + delResult[i].errors.message + '</td></tr>';
        }
      }
      msgFailedReason += '</table></div>';
      
      message = 
        '<b>Record(s) Submitted</b> : ' + selectedRecords.length + '<br/>' + 
        '<b>Record(s) Deleted</b> : ' + passCount + '<br/>' +
        '<b>Failed Record(s)</b> : ' + failCount + '<br/>';

      if(failCount > 0)
        message += msgFailedReason;

      message += '<p align="center"><button class="btn" onclick="window.parent.resultWnd.hide(); window.parent.location.reload(); return false;">Close</button></p>';

      var resultWnd = new SimpleDialog("Mass-Delete-QL-" + Dialogs.getNextId(), false);
      resultWnd.setTitle("Status - Mass Delete Quote Line Items");
      resultWnd.createDialog();
      window.parent.resultWnd = resultWnd;
      resultWnd.setContentInnerHTML(message);
      resultWnd.show();
    }
  }
}
catch(e)
{
  alert('The Action Could not be Completed. Error Message: ' + e);
}

Save it
You now will have to add it to the Quote Line Items Related List.
Navigate to - Quote record - edit Layout - Add button on to the Quote Line Items Related List by clicking the Wedge icon on the Related List.

Rgrds,
Rabi
 
This was selected as the best answer
Shirley Lafuente 6Shirley Lafuente 6
Rabi,
This works wonderful!  Our sales team is going to be sooooo happy.  Thanks so much.
Eric Cottone 9Eric Cottone 9
Rabi,

This works great!  Thank you!
Eric Cottone 9Eric Cottone 9
Here is the same javascript edited to work for OpportunityLineItem.  Change the object type in line 4 to match the object where you are adding the button.
 
{!REQUIRESCRIPT('/soap/ajax/29.0/connection.js')}
try
{
  var selectedRecords = {!GETRECORDIDS( $ObjectType.OpportunityLineItem )};
  if(selectedRecords.length < 1)
    alert('Please Select at Least One Row !');
  else
  {
    userConsent = confirm(selectedRecords.length + ' Record(s) will be Deleted. Continue ? ');
    if(userConsent == true)
    {
      delResult = sforce.connection.deleteIds(selectedRecords);
      
      var message = '';
      var msgFailedReason = '<br/><h3>Failed Record(s)</h3><br/><div style="height: 300px;overflow-y: scroll;"><table style="border-collapse: collapse;">';
      var passCount = 0, failCount = 0;
      for(var i=0; i < delResult.length; i++){
        if(delResult[i].getBoolean('success')){
          passCount++;
        }
        else{
          failCount++;
          msgFailedReason += '<tr><td style="vertical-align: top; border-bottom: 1px solid gray;">' + delResult[i].errors.message + '</td></tr>';
        }
      }
      msgFailedReason += '</table></div>';
      
      message = 
        '<b>Record(s) Submitted</b> : ' + selectedRecords.length + '<br/>' + 
        '<b>Record(s) Deleted</b> : ' + passCount + '<br/>' +
        '<b>Failed Record(s)</b> : ' + failCount + '<br/>';

      if(failCount > 0)
        message += msgFailedReason;

      message += '<p align="center"><button class="btn" onclick="window.parent.resultWnd.hide(); window.parent.location.reload(); return false;">Close</button></p>';

      var resultWnd = new SimpleDialog("Mass-Delete-QL-" + Dialogs.getNextId(), false);
      resultWnd.setTitle("Status - Mass Delete Quote Line Items");
      resultWnd.createDialog();
      window.parent.resultWnd = resultWnd;
      resultWnd.setContentInnerHTML(message);
      resultWnd.show();
    }
  }
}
catch(e)
{
  alert('The Action Could not be Completed. Error Message: ' + e);
}

 
Rick Burmeister 5Rick Burmeister 5
Is there a way to do this with Professional Edition.  I followed these direction above, but my button would not do anything (using Chrome).  I then tried in IE and I received the message that I needed API enabled.  I assume this is because I am only PE?  Any hope for me?  This is a powerful button if I could get it working.  Thanks for any thoughts!
Phil SaundersPhil Saunders
This is exaclty what we are after, but I can't seem to get it to work. I get a JavaScipt error saying "Unexpected Number". Help please? I am trying to do this for the opportunity products field. Thanks in advance. 
Patricia BoycePatricia Boyce
I would like to know how to do this in Lightning?
Mark PittsMark Pitts
I'd like to know why I am getting the error: "a problem with the onclick javascript.... unexpected end of input"
 
{!REQUIRESCRIPT('/soap/ajax/29.0/connection.js')}
try
{
  var selectedRecords = {!GETRECORDIDS( $ObjectType.QuoteLineItem )};
  if(selectedRecords.length < 1)
    alert('Please Select at Least One Row !');
  else
  {
    userConsent = confirm(selectedRecords.length + ' Record(s) will be Deleted. Continue ? ');
    if(userConsent == true)
    {
      delResult = sforce.connection.deleteIds(selectedRecords);
      
      var message = '';
      var msgFailedReason = '<br/><h3>Failed Record(s)</h3><br/><div style="height: 300px;overflow-y: scroll;"><table style="border-collapse: collapse;">';
      var passCount = 0, failCount = 0;
      for(var i=0; i < delResult.length; i++){
        if(delResult[i].getBoolean('success')){
          passCount++;
        }
        else{
          failCount++;
          msgFailedReason += '<tr><td style="vertical-align: top; border-bottom: 1px solid gray;">' + delResult[i].errors.message + '</td></tr>';
        }
      }
      msgFailedReason += '</table></div>';
      
      message = 
        '<b>Record(s) Submitted</b> : ' + selectedRecords.length + '<br/>' + 
        '<b>Record(s) Deleted</b> : ' + passCount + '<br/>' +
        '<b>Failed Record(s)</b> : ' + failCount + '<br/>';

      if(failCount > 0)
        message += msgFailedReason;

      message += '<p align="center"><button class="btn" onclick="window.parent.resultWnd.hide(); window.parent.location.reload(); return false;">Close</button></p>';

      var resultWnd = new SimpleDialog("Mass-Delete-QL-" + Dialogs.getNextId(), false);
      resultWnd.setTitle("Status - Mass Delete Quote Line Items");
      resultWnd.createDialog();
      window.parent.resultWnd = resultWnd;
      resultWnd.setContentInnerHTML(message);
      resultWnd.show();
    }
  }
}
catch(e)
{
  alert('The Action Could not be Completed. Error Message: ' + e);

 
KPJSKPJS
All these great buttons for Classic. Nothing as easy for Lightning!!