You need to sign in to do that
Don't have an account?
Satya413
Refresh VF Page after method executes
Hi,
I need to refresh the whole VF Page once my delete method executes. I have wriiten the below code. When I delete a particular record, the record is getting deleted but the page is not refreshing to show the updated records. Please help.
VF Page:
<apex:page controller="viewdept_con" showHeader="false " id="mypage">
<apex:form >
<apex:pageBlock >
<apex:pageblockTable value="{!deptlist}" var="item">
<apex:column headerValue="Action">
<apex:commandLink value="Detail" action="{!deptdetail}"/><b> | </b>
<apex:commandLink value="Del" action="{!deptdelete}" reRender="mypage">
<apex:param name="deptid" value="{!item.id}" assignTo="{!deptid}"/>
</apex:commandlink>
</apex:column>
<apex:column value="{!item.name}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class viewdept_con {
public list<department__c> deptlist { get; set; }
public id deptid {get; set;}
public department__c dept {get; set;}
public viewdept_con()
{
deptlist = [select id, name from department__c];
}
public pagereference deptdetail()
{
pagereference pg = new pagereference('/apex/DepartmentDetail?deptid=' + deptid);
return pg;
}
public pagereference deptdelete()
{
dept = [select id, name from department__c where id = :deptid];
delete dept;
return null;
}
}
Thank you,
Satya
I need to refresh the whole VF Page once my delete method executes. I have wriiten the below code. When I delete a particular record, the record is getting deleted but the page is not refreshing to show the updated records. Please help.
VF Page:
<apex:page controller="viewdept_con" showHeader="false " id="mypage">
<apex:form >
<apex:pageBlock >
<apex:pageblockTable value="{!deptlist}" var="item">
<apex:column headerValue="Action">
<apex:commandLink value="Detail" action="{!deptdetail}"/><b> | </b>
<apex:commandLink value="Del" action="{!deptdelete}" reRender="mypage">
<apex:param name="deptid" value="{!item.id}" assignTo="{!deptid}"/>
</apex:commandlink>
</apex:column>
<apex:column value="{!item.name}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class viewdept_con {
public list<department__c> deptlist { get; set; }
public id deptid {get; set;}
public department__c dept {get; set;}
public viewdept_con()
{
deptlist = [select id, name from department__c];
}
public pagereference deptdetail()
{
pagereference pg = new pagereference('/apex/DepartmentDetail?deptid=' + deptid);
return pg;
}
public pagereference deptdelete()
{
dept = [select id, name from department__c where id = :deptid];
delete dept;
return null;
}
}
Thank you,
Satya
Their are 2 ways to refresh deleted records.
#1. after deleting your records, you can again initilize deptlist by querying records same as you are doing in constructor. Actually when your methods has return null it will not call constructor again and will not initalize list.
#2. Implement delete methods to return VF page reference and set is redirect true like below.
hope that will help
Thanks!
All Answers
Thanks for your reply. I have tried removing the rerender element but it still remains the same. The page seems to refresh, however it still shows the deleted record.
Thank you,
Satya
Their are 2 ways to refresh deleted records.
#1. after deleting your records, you can again initilize deptlist by querying records same as you are doing in constructor. Actually when your methods has return null it will not call constructor again and will not initalize list.
#2. Implement delete methods to return VF page reference and set is redirect true like below.
hope that will help
Thanks!
Thanks for your response. It worked. Below is my code.
public pagereference deptdelete()
{
dept = [select id, name from department__c where id = :deptid];
delete dept;
pagereference pg = new pagereference('/apex/ViewDepartment');
pg.setredirect(true);
return pg;
}
Thank you,
Satya