You need to sign in to do that
Don't have an account?
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
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!
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;
}
OK it was an issue on variable initialization
Thanks
Regards