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
DorababuDorababu 

Problem with Redirecting on Standard Delete Link

Hi,

I have overriden the delete link of a custom object to redirect to a custom vf page. The custom page shows the members associated with the custom object. When members are associated delete is not possible - user has to remove members and then delete the record of custom object. The problem is when there are no members associated with the object even then user is redirected to custom page. I need to have a control on redirect such that, only when members are associated, redirect happens and when members are not associated redirect should not happen and selected record should be deleted.

Any solution would be appreciated.

Anil SavaliyaAnil Savaliya

Hi Krishna,

 

<apex:page  controller="XYZ"  action="{!DeleteWithOutRender}"  rendered="{!DoNotOpen}">

All UI for member available

</apex:page>

 

Public class XYZ{

public boolean DonotOpen {get;set;}

public void DeletewithOutRender (){

 

if(member > 0){

DoNotOpen = true ;

}

Else{

DoNotOpen = False;

delete record  ;

}

}

 

}

 

If it's work,Please add in Kudos.

DorababuDorababu
-------------- Controller --------------------


public with sharing class householdDeleteController {
    public Household_Group__c hg{get;set;}
     public List<Household_Member__c> memberList;
     public List<Account> acc{get; set;}
     public Id hgid{get;set;}
     public set<id> memids{get;set;}
     
     public boolean DonotOpen {get;set;}
     
     ApexPages.StandardController con;
     
     public householdDeleteController()
    {
    }

    public householdDeleteController(ApexPages.StandardController controller) {
        con = controller;
        this.hg =(Household_Group__c) controller.getRecord();
        hgid = ApexPages.CurrentPage().getParameters().get('id');
        memberList = new List<Household_Member__c>();
        
        
        memberList= [select id,Household_Group__c,Member__C,name from Household_Member__c where Household_Group__c =:hgid];

    Set<id> memids = new Set<id>();
   
    for(Household_Member__c h:memberList)
    {
    memids.add(h.Member__c);
     }
     if(memids.isEmpty())
     {
         DeletewithOutRender();
         
     }
     acc = new List<Account>([Select name from Account where id in: memids]);
    system.debug('@@@@@@@@@@@'+acc);
    
   //Integer count = memids.size();     
        
    }
    public void DeletewithOutRender()
    {
        delete hg;
        
    /*PageReference page = new Pagereference('/apex/HouseholdDetail?id='+hgid);
         page.setRedirect(true);
        return page;*/
    
    }
    
    public void DeletewithOutRender(Set<Id> x){
 
        if(x.size() > 0){
        DoNotOpen = true ;
        }
        Else{
        DoNotOpen = False;
        delete hg;
        }
    }
    
    public pageReference backtorecord(){
    PageReference pageRef = new PageReference('/apex/HouseholdDetail?id='+hgid);
    pageRef.setRedirect(true);
    return pageRef;
    }
   
    
     public List<Account> getMembers()
    {
    system.debug('@@@@@@@@@@@'+acc);
    return acc;
    
    }
    

}

 page

<apex:page standardController="Household_Group__c" showHeader="true" extensions="householdDeleteController" action="{!DeletewithOutRender}" rendered="{!DoNotOpen}" >
  <apex:sectionHeader title="Household Delete" subtitle="{!Household_Group__c.Name}" help="http://www.salesforce.com"/>
      <apex:form >
      <apex:commandLink action="{!backtorecord}"> « Back to List: Households </apex:commandLink>
      
      <p><apex:outputLabel value="{!$Label.bmo_page_hhdeletemsg}"></apex:outputLabel></p>
      <!--<apex:pageMessage severity="error" strength="2">Your attempt to delete "{!$ObjectType.Household_Group__c.Name}" could not be completed because it is associated with the following household members. If the following table is empty, it's because you don't have access to the records restricting the delete.
      </apex:pageMessage>-->
      
      <apex:pageBlock id="pb">
     <apex:pageblockTable id="hhtable"  value="{!Members}" var="mem" width="80%" >
          <apex:column value="{!mem.Name}"/>
         <!-- <apex:column value=""/> -->
      
      </apex:pageblockTable>  
      </apex:pageBlock>
      
      </apex:form>
</apex:page>

 System.LimitException: DML currently not allowed 

 

Class.householdDeleteController.DeletewithOutRender: line 78, column 1
Class.householdDeleteController.<init>: line 33, column 1

 

How can i avoid the above exception?

sguptasgupta
You can't use DML in constructor method of the controller..