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
Aravind RAravind R 

How to refresh the pagetableblock after clicking commandlink??

I want to have latest values after clicking "Remove interest".. Code is working perfectly but I am able to see only after refreshing on my own

My vf page is:

<apex:page standardController="Aspirant__c" extensions="displayRelatedlists">
<apex:form >
<apex:pageBlock id="blk">
<apex:pageBlockTable value="{!prsns}" var="pr">
<apex:column value="{!pr.Name__c}" />
<apex:column >
<apex:facet name="header">Remove Interest</apex:facet>
<apex:commandLink value="Remove Interest" action="{!removeInterest}" reRender="blk" >
<apex:param assignTo="{!aspId}" name="aspId" value="{!pr.Id}" />
</apex:commandLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>


apex class:

public class displayRelatedlists{
public ApexPages.StandardController controller{get;set;}
public Aspirant__c asps{get;set;}
public List<Interested_Persons__c> prsns{get;set;}
public String aspId{get;set;}
public displayRelatedlists(ApexPages.StandardController controller)
{
this.controller = controller;
this.asps= (Aspirant__c)controller.getRecord();
this.prsns = [SELECT Name__c from Interested_Persons__c where Interested_To__c=:asps.Id];
}
public PageReference removeInterest()
{
system.debug('++++++++++++++++++++ '+aspId);
Interested_Persons__c ipc = [select Id,Name__c from Interested_Persons__c where Id=:aspId];
delete ipc;
return null;
}

}
Best Answer chosen by Aravind R
Vamsi KrishnaVamsi Krishna
hmm.. just reading the code again, your pageblock table displays the interested persons for a given aspirant initially..
and the remove link is just removing a single interested person from the list..
so instead of clearing the entire list, if you reload your collection after deleting the single record, it should get updated in the table as well..

public PageReference removeInterest()
{
system.debug('++++++++++++++++++++ '+aspId);
Interested_Persons__c ipc = [select Id,Name__c from Interested_Persons__c where Id=:aspId];
delete ipc;
this.prsns = [SELECT Name__c from Interested_Persons__c where Interested_To__c=:asps.Id];
return null;
}

All Answers

Vamsi KrishnaVamsi Krishna
hmm.. just reading the code again, your pageblock table displays the interested persons for a given aspirant initially..
and the remove link is just removing a single interested person from the list..
so instead of clearing the entire list, if you reload your collection after deleting the single record, it should get updated in the table as well..

public PageReference removeInterest()
{
system.debug('++++++++++++++++++++ '+aspId);
Interested_Persons__c ipc = [select Id,Name__c from Interested_Persons__c where Id=:aspId];
delete ipc;
this.prsns = [SELECT Name__c from Interested_Persons__c where Interested_To__c=:asps.Id];
return null;
}

This was selected as the best answer
Aravind RAravind R
Thank you Vamshi.. Its working