You need to sign in to do that
Don't have an account?
ahammad sk
Custom Visualforce Delete page for multiple records, Delete link is not working.
Hi,
In Custom Visualforce Delete page for multiple records, when click on Delete link that recordID is not passing to controller.
For Single record Delete link is working , here recordID is passing to controller(passing recordid through url).
But for Multiple records when click on Delete link the recordid is not passing to controller.
please help on the issue.
Visualforce page:
<apex:page standardController="contact" extensions="deletemultiplecont" recordSetVar="contacts" >
<apex:form >
<apex:pageblock >
<table class="list " border="0" cellpadding="0" cellspacing="0">
<tr class="headerRow" >
<th class="headerRow"> Action </th>
<th class="headerRow"> Name </th>
<th class="headerRow"> MailingCity </th>
<th class="headerRow"> Phone </th>
</tr>
<th> <apex:repeat value="{!contacts}" var="cont">
<tr class="dataRow">
<td class="dataCell"> <apex:commandlink value="delete" action="{!delmultplerec}">
<apex:param value="{!cont.id}" assignTo="{!asgn}"/>
</apex:commandLink> </td>
<td class="dataCell"> <apex:outputText value="{!cont.Name}"/> </td>
<td class="dataCell"> <apex:outputText value="{!cont.MailingCity}"/> </td>
<td class="dataCell"> <apex:outputText value="{!cont.phone}"/> </td>
</tr>
</apex:repeat> </th>
</table>
</apex:pageblock>
</apex:form>
</apex:page>
Apex:
Public with sharing class deletemultiplecont
{
public string Name{set;get;}
public string Phone{get;set;}
public string MailingCity{get;set;}
public string asgn{get;set;}
public contact cdel = new contact();
public deletemultiplecont(apexpages.standardsetcontroller setcon)
{
}
Public pagereference delmultplerec()
{
system.debug('hidden val is..!!' +asgn);
try
{
cdel = [select id from contact where id =: asgn];
system.debug('delete rec is..!!' +cdel);
delete cdel;
return NULL;
}
catch(exception e)
{
System.debug('The following exception has occurred: ' + e.getMessage());
return NULL;
}
}
}
In Custom Visualforce Delete page for multiple records, when click on Delete link that recordID is not passing to controller.
For Single record Delete link is working , here recordID is passing to controller(passing recordid through url).
But for Multiple records when click on Delete link the recordid is not passing to controller.
please help on the issue.
Visualforce page:
<apex:page standardController="contact" extensions="deletemultiplecont" recordSetVar="contacts" >
<apex:form >
<apex:pageblock >
<table class="list " border="0" cellpadding="0" cellspacing="0">
<tr class="headerRow" >
<th class="headerRow"> Action </th>
<th class="headerRow"> Name </th>
<th class="headerRow"> MailingCity </th>
<th class="headerRow"> Phone </th>
</tr>
<th> <apex:repeat value="{!contacts}" var="cont">
<tr class="dataRow">
<td class="dataCell"> <apex:commandlink value="delete" action="{!delmultplerec}">
<apex:param value="{!cont.id}" assignTo="{!asgn}"/>
</apex:commandLink> </td>
<td class="dataCell"> <apex:outputText value="{!cont.Name}"/> </td>
<td class="dataCell"> <apex:outputText value="{!cont.MailingCity}"/> </td>
<td class="dataCell"> <apex:outputText value="{!cont.phone}"/> </td>
</tr>
</apex:repeat> </th>
</table>
</apex:pageblock>
</apex:form>
</apex:page>
Apex:
Public with sharing class deletemultiplecont
{
public string Name{set;get;}
public string Phone{get;set;}
public string MailingCity{get;set;}
public string asgn{get;set;}
public contact cdel = new contact();
public deletemultiplecont(apexpages.standardsetcontroller setcon)
{
}
Public pagereference delmultplerec()
{
system.debug('hidden val is..!!' +asgn);
try
{
cdel = [select id from contact where id =: asgn];
system.debug('delete rec is..!!' +cdel);
delete cdel;
return NULL;
}
catch(exception e)
{
System.debug('The following exception has occurred: ' + e.getMessage());
return NULL;
}
}
}
If nothing works for you, then try below code (I have added only 2 lines shown below as underline in apex class and change 1 line in visual force page):
Page: (Removed assignTo attribute and added name attribute)
<apex:param value="{!cont.id}" name="Id" />
Apex:
Public with sharing class deletemultiplecont
{
public string Name{set;get;}
public string Phone{get;set;}
public string MailingCity{get;set;}
public string asgn{get;set;}
public contact cdel = new contact();
public deletemultiplecont(apexpages.standardsetcontroller setcon)
{
}
Public pagereference delmultplerec()
{
Id contactId = apexpages.currentpage().getParameters().get('Id');
system.debug('hidden val is..!!' +asgn);
try
{
cdel = [select id from contact where id =: contactId];
system.debug('delete rec is..!!' +cdel);
delete cdel;
return NULL;
}
catch(exception e)
{
System.debug('The following exception has occurred: ' + e.getMessage());
return NULL;
}
}
}
Warm Regards,
Darshan Shah
All Answers
If you want to pass a value in controller then you have us "Rerender" attribute of CommanLink tag. By this when you click on link it will pass the value and your controller perform the action and in last on page your section will refresh (only that section will refresh whose id you have passed in Rerender=<Id of Section>.
Here is script.
Update below tag Then update command link
Now try and let me know.
If this info solve your problem, please mark it as a solution.
Thanks
Ashlekh
Ashlesh i sright you need to reRender on click of the link to get the id in controller . One more issue is you have declared the varibale as string and getting and passing Id which is also one issue what I observe .
Is is a project related thing or a dummy code you are testing if testing it is ok else you need yo use pagination using standardset controller method which will show you all contacts .Currently you will see only 20 contacts in your page .
You can check with below code it will help you .
If nothing works for you, then try below code (I have added only 2 lines shown below as underline in apex class and change 1 line in visual force page):
Page: (Removed assignTo attribute and added name attribute)
<apex:param value="{!cont.id}" name="Id" />
Apex:
Public with sharing class deletemultiplecont
{
public string Name{set;get;}
public string Phone{get;set;}
public string MailingCity{get;set;}
public string asgn{get;set;}
public contact cdel = new contact();
public deletemultiplecont(apexpages.standardsetcontroller setcon)
{
}
Public pagereference delmultplerec()
{
Id contactId = apexpages.currentpage().getParameters().get('Id');
system.debug('hidden val is..!!' +asgn);
try
{
cdel = [select id from contact where id =: contactId];
system.debug('delete rec is..!!' +cdel);
delete cdel;
return NULL;
}
catch(exception e)
{
System.debug('The following exception has occurred: ' + e.getMessage());
return NULL;
}
}
}
Warm Regards,
Darshan Shah
Thanks your replay,
I tried with "rerender" in commandlink but the record is not deleted. I think rerender works for commandbutton.
by changing the following code, The record is deleted only if manually refresh the page.
Page:
Removed assignTo attribute and added name attribute
<apex:param value="{!cont.id}" name="Id" />
Apex:
Id contactId = apexpages.currentpage().getParameters().get('Id');
cdel = [select id from contact where id =: contactId];
delete cdel;
When I click on Delete link the record is deleted in backend, but in UI the record remain same. After manually refresh the page
then only the record is deleted.
How can I refresh the page after Delete operation in Action method.
Please help on the issue...
Vf page:
<apex:page standardController="contact" extensions="deletemultiplecont" recordSetVar="contacts" >
<apex:form id="frm">
<apex:pageblock id="pgblk">
<table class="list " border="0" cellpadding="0" cellspacing="0">
<tr class="headerRow" >
<th class="headerRow"> Action </th>
<th class="headerRow"> Name </th>
<th class="headerRow"> MailingCity </th>
<th class="headerRow"> Phone </th>
</tr>
<th> <apex:repeat value="{!contacts}" var="cont">
<tr class="dataRow">
<td class="dataCell"> <apex:commandlink value="delete" action="{!delmultplerec}">
<apex:param value="{!cont.id}" name="ctid"/>
</apex:commandLink> </td>
<td class="dataCell"> <apex:outputText value="{!cont.Name}"/> </td>
<td class="dataCell"> <apex:outputText value="{!cont.MailingCity}"/> </td>
<td class="dataCell"> <apex:outputText value="{!cont.phone}"/> </td>
</tr>
</apex:repeat> </th>
</table>
</apex:pageblock>
</apex:form>
</apex:page>
Apex:
Public with sharing class deletemultiplecont{
public string Name{set;get;}
public string Phone{get;set;}
public string MailingCity{get;set;}
// public id asgn{get;set;}
public contact cdel = new contact();
public contact cont{get;set;}
public deletemultiplecont(apexpages.standardsetcontroller setcon)
{
}
Public pagereference delmultplerec()
{
Id contactId = apexpages.currentpage().getParameters().get('Id');
system.debug('hidden val is..!!' +contactId );
try
{
cdel = [select id from contact where id =: contactId];
system.debug('delete rec is..!!' +cdel);
delete cdel;
return NULL;
}
catch(exception e)
{
System.debug('The following exception has occurred: ' + e.getMessage());
return NULL;
}
}
}
I got the solution for refresh the page after DML operation. In Commandlink we have oncomplete = "location.reload();"
<apex:commandlink value="delete" action="{!delmultplerec}" oncomplete = "location.reload();">
Now its working. When click on delete link the record is deleted.
Thanks