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
lawlaw 

How to Refresh custom VF page after delete

Hello I have PageBlockTable with in line editing and a link to delete the selected row.
The delete works fine, however I cannot figure our how to refresh the page or even just the
pageblocktable to show that the row has been deleted.

 

Thanks in Advance

 

Delete method:

public string SelectedDetailId { get; set; }
public void DeleteDetail()
{
if (SelectedDetailId == null) {
return;
}
Product_Detail__c toBeDeleted = [SELECT name FROM Product_Detail__c WHERE Name = :SelectedDetailId LIMIT 1];
if (toBeDeleted != null) delete toBeDeleted;
//refreshTable();

}

 

 

Apex Code:

<apex:pageBlockTable id="annTable" value="{!AnnuityProducts}" var="item" Title="Annuity Detail">

<apex:column >
<a href="javascript&colon;if (window.confirm('Are you sure?')) DeleteDetail('{!item.name}');" style="font-weight:bold">Del</a>
</apex:column>

<apex:column headerValue="Carrier">
<apex:outputField value="{!item.Name__c}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>

<apex:column headerValue="Type">
<apex:outputField value="{!item.Type__c}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>

<apex:column headerValue="Verified Assets">
<apex:outputField value="{!item.Asset_Total__c}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>

<apex:column headerValue="Portability">
<apex:outputField value="{!item.Portability__c}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>

<apex:column headerValue="Product Detail Name">
<apex:outputField value="{!item.Name}">

</apex:outputField>
</apex:column>
</apex:pageBlockTable>

<apex:actionFunction action="{!DeleteDetail}" name="DeleteDetail" reRender="test" >
<apex:param name="name" value="" assignTo="{!SelectedDetailId}"/>
</apex:actionFunction>

Best Answer chosen by Admin (Salesforce Developers) 
lawlaw

Hello

 

Thanks to everyone for there help.  Based on Baktash H suggestion , the following code works!

 

public PageReference refreshTable() {  
    PageReference curPage = Page.DD_BOB;
    curPage.getParameters().put('id', bob.id);
    curPage.setRedirect(true);
    return curPage;
   } 

All Answers

Baktash H.Baktash H.

rerender the pageblocktable. in your actionfunction is the rerender attrubite 'test'. So the id of the pageblocktable has to be 'test'

lawlaw

Baktash

 

The id of the pageBlock  in the above code is 'annTable'.  I changed the reRender from 'test' to 'annTable'.  Still no Refresh.

 

 

Baktash H.Baktash H.

try putting the datatable in an actionregion tag.

lawlaw

I put the pageblockTable in the actionRegion tag and same results... no refresh.

cduncombe44cduncombe44

Try putting the entire table in <apex:outputPanel id="panel">.  Then refresh the panel.  

 

Chris

lawlaw

Hello

 

 

This did not work either.

Baktash H.Baktash H.

To refresh the whole page set the return type of the function to PageReference and redirect to the current page.

lawlaw

I added the following to my delete method  shown above.

 

PageReference curPage = ApexPages.currentPage();
curPage.setRedirect(true);
return curPage;

 

I received the following error message when attempting to save....

 

"Error: Compile Error: Void method must not return a value at line 282 column 5"

 

cduncombe44cduncombe44
You need to make your method return a pagereference Public pagereference yourMethodName()
lawlaw

When I change it from  Void  to Public ...  the delete doesn't work.  I receive other errors messages....

Baktash H.Baktash H.

the return type of you method has to be PageReference.

 

public Pagereference methodName(){

 

           PageReference p = new PageReference('/PageName');
            p.setRedirect(true);
            return p;

}

S91084S91084

Hi, Surround your pageblock table with an <apex:outputpanel>  </apex:outputpanel> tag and use that id of that panel and the pageblock Id in the rerender attribute of  you <apex:actionFunction/>

lawlaw

You mean something like this

 

public PageReference refreshTable() {
PageReference curPage = ApexPages.currentPage();
curPage.setRedirect(true);
return curPage;
}

 

I receive no errors, but the page doesn't refresh either.

lawlaw

The output panel was suggested previously and did not work.

lawlaw

Here's the code for the output panel:

 

<apex:outputPanel id="panel">
<apex:pageBlockTable id="annTable" value="{!AnnuityProducts}" var="item" Title="Annuity Detail">

<apex:column >
<!-- <apex:outputLink title="" value="/{!row.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp; -->
<a href="javascript&colon;if (window.confirm('Are you sure?')) DeleteDetail('{!item.name}');" style="font-weight:bold">Del</a>
</apex:column>

<apex:column headerValue="Carrier">
<apex:outputField value="{!item.Name__c}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>

<apex:column headerValue="Type">
<apex:outputField value="{!item.Type__c}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>

<apex:column headerValue="Verified Assets">
<apex:outputField value="{!item.Asset_Total__c}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>

<apex:column headerValue="Portability">
<apex:outputField value="{!item.Portability__c}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>

</apex:pageBlockTable>
</apex:outputpanel>

<apex:actionFunction action="{!DeleteDetail}" name="DeleteDetail" reRender="annTable,panel">
<apex:param name="name" value="" assignTo="{!SelectedDetailId}"/>
</apex:actionFunction>

lawlaw

Hello

 

Thanks to everyone for there help.  Based on Baktash H suggestion , the following code works!

 

public PageReference refreshTable() {  
    PageReference curPage = Page.DD_BOB;
    curPage.getParameters().put('id', bob.id);
    curPage.setRedirect(true);
    return curPage;
   } 

This was selected as the best answer