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
alex_from_75015alex_from_75015 

Visualforce that display a list of object and a delete link for each line

Hello

I am using <apex:repeat> to display an agregation of field from different object linked to a main one

I want to add a delete link and I am getting crazy

I have tried this :

<td><apex:outputLink title="" value="{!myurl}&delId={!CampaignMember[idx].Id}" target="_blank" style="font-weight:bold">Remove</apex:outputLink></td>

-> that cause DML currently not allowed by treating delId parameter in main controller

 

Some post said to treat it in apex:page action {!deletemyobject} : same result DML currently not allowed

 

Then I have tried ajax

<td><apex:commandLink onclick="deleteCM('{!CampaignMember[idx].Id}')" value="Delete"/></td>

Works well for deletion but refreshing does not work : either line is not deleted on refresh, either I have everyline in double

 

Can someone help me with such a simple need ?

By the way if some has code for checkbox for each line to perform an action or select all checkbox like SFDC view, I am interested instead of rebuilding everything

 

Thanks for your help


kerwintangkerwintang

Have you tried to create an actionFunction for this?

 

<apex:actionFunction name="deleteRecord" action="{!deleteRecord}" rerender="recordsTable">
        <apex:param name="recordId" value=""/>
</apex:actionFunction>

 

just ensure that the table that you want to refresh is inside the apex:pageBlock with id="recordsTable" (the one you mentioned in the actionFunction).

 

then on each record in your table, make the Delete object inside a commandLink with onclick="deleteRecord(recordId)".

 

Hope this helps!

alex_from_75015alex_from_75015

Hi

This method works well except that it re-displays deleted line and triple all my line

Let's say I have 5 line, I delete 1, 15 appears on rerendered !!! but if I refresh page I have 4 lines

It has same behaviour as my previous ajax code (but nicer in controller)

 

Here is my code

 

<apex:pageBlock>
<apex:actionFunction name="deleteRecord" action="{!deleteRecord}" rerender="CampaignMember">
        <apex:param name="recordId" assignTo="{!recordId}" value=""/>
</apex:actionFunction>
<table>
<apex:repeat var="idx" value="{!indexes}" id="CampaignMember">
  <tr>

<td>
    <apex:commandLink onclick="deleteRecord('{!CampaignMember[idx].Id}')" value="Delete"/>
    </td>

</tr>
</apex:repeat>
</table>
</apex:pageBlock>

 

 

Apex class

 

public void deleteRecord() {
         CampaignMember mycmtmp=[select id from CampaignMember where id=:recordId];
        delete mycmtmp;

  }

alex_from_75015alex_from_75015

OK it was an issue on variable initialization

Thanks

Regards