Apex checkbox to select and delete raws in interactive report

62 Views Asked by At

I'm just starting with Apex,

I just need to link a delete button to the checkbox in an interactive report, in order to delete the selected raws.

This is the report source (SQL query):

select CUSTOMER_LEGAL_ID,
   CUSTOMER_FIRST_NAME,
   CUSTOMER_MIDDLE_NAME,
   CUSTOMER_LAST_NAME,
   CUSTOMER_ADDRESS,
   CUSTOMER_PHONE_NUMBER,
   CREATED_BY,
   CREATION_DATE,
   LAST_UPDATE_BY,
   LAST_UPDATE_DATE,
   apex_item.CHECKBOX2(02, CUSTOMER_LEGAL_ID) sel

from TEST_CUSTOMERS

I've set the button behavior on "Defined by Dynamic Action" and "SQL DELETE action" but now I have to link the button to the checkbox.

Thanks in advance.

1

There are 1 best solutions below

0
Koen Lostrie On

There are 2 approaches to this (probably more). The first one is to use apex_item to render the checkbox and use a page process to delete the buttons on refresh. The 2nd one is to use some kind of array (apex collection on the server or js array) and then use dynamic action to perform the delete and refresh.

You are trying to mix both which is not going to work...

The solution to doing it with apex_item is described in this stack overflow answer. It's not exactly the same but you'll have to follow the same logic: add a column with a hidden item to your query use a button to submit the page (not a dynamic action) and process the selected items in a page process. Let me know if you have questions about how to do that.

Note that the solution using apex_item does not support pagination. It is completely serverside code and only processes the records on the screen. It will not "remember" rows checked on the previous page.

The 2nd solution is to use a technique similar to described here. This is for an interactive grid but it probably can be adapted for an interactive report as well.

I'd suggest to have a look at the apex dynamic actions sample app - the "Delete and refresh" example could also be useful. That approach is my favorite, but it's a row by row delete, not a checkbox with option of multiselects.