I have a requirement where we perform "Mass delete" for records in one of the related list (Custom object called Recipient__c) from the parent object (Parent Object called FundCommunication__c).

It looks like above one

My VF Page:

<apex:page standardController="Recipient__c" extensions="MassDeleteRecipientscontroller" recordSetVar="Documents">
    <apex:pageMessages ></apex:pageMessages>
    <apex:form rendered="{!NOT(hasErrors)}">
        <apex:outputText value="Are you certain you want to delete these Recipients?" />
        <p style="font-size:18px;"/>
        <apex:commandButton value="Ok" action="{!deleteSelectedRecipient}" rendered="{!showOkButton}"/>
        <apex:commandbutton action="{!redirectToRecord}" style="margin-left:30%;" value="Back to Fund communication" rendered="{!showReturnButton}" />

After I Click on 'Ok', the selected records are deleted. After that If I click on 'Back to fund communication button', the page is getting navigated back to the Fund Communication record, but the related list for which the records are deleted are not getting updated until I refresh. (The records which are deleted are still appearing). Not sure if this a caching issue.

Below is my controller:

public class MassDeleteRecipientscontroller {
    public static String EMPTY_SELECTION = 'No Recipients selected.';
    public static String DELETE_SUCCESS = 'Recipients were deleted successfully.';
    private ApexPages.StandardSetController standardSetController;
    private List<Recipient__c> selectedRecipients;
    public Boolean hasErrors {get; set;}
    private Id fundCommunicationId;
    public Boolean showOkButton {get; set;}
    public Boolean showReturnButton {get; set;}
    public MassDeleteRecipientscontroller(ApexPages.StandardSetController standardSetController) {
        this.hasErrors = false;
        this.standardSetController = standardSetController;
        this.selectedRecipients = standardSetController.getSelected();
        this.showOkButton = true;
        Id RecipientId = this.selectedRecipients[0].Id;
        if (selectedRecipients.isEmpty()) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, EMPTY_SELECTION));
            this.hasErrors = true;
        List<Recipient__c> recipientList = [SELECT Id, fund_communication__r.Id FROM Recipient__c where Id =: RecipientId];
        this.fundCommunicationId = recipientList[0].fund_communication__r.Id;
        system.debug('Fund communication id is '+this.fundCommunicationId);
    public PageReference deleteSelectedRecipient() {
        System.debug('Deleting: ' + this.selectedRecipients);
        delete this.selectedRecipients;
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, DELETE_SUCCESS));
            showOkButton = false;
            showReturnButton = true;
        catch(exception e){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage()));
        return null;
    public pageReference redirectToRecord(){
        //Id RoundDetailId = this.standardController.getId();
       PageReference pageRef = new PageReference('/' + fundCommunicationId);
       return pageRef;


You must log in to answer this question.