0

I have a VF page displaying a custom object with it's child objects in repeating apex:detail sections. Each section displays the child with the standard edit, delete,clone buttons that are there like when you open the child object by itself. enter image description here

Everything works fine, except when clicking delete (to delete one of the child objects), which does delete the child but doesn't return to the parent VF page.

I tried creating a VF + controller to override the std delete button on the child, but the parameter it passes is the parent's one, and I get this error:

Id value a02O000000DdrPj is not valid for the CallCycleActivity__c standard controller

The id is for the parent, and CallCycleActivity__c is the child which is being deleted.

I need to delete the child and to return to the parent. How do I get it do this?

<apex:page standardController="CallCycleActivity__c" extensions="CCADeleteOverrideExt" action="{!customDelete}">

public with sharing class CCADeleteOverrideExt {

private CallCycleActivity__c cca;    
public PageReference pageRef;
public Map<string,string> URLParameters = ApexPages.currentPage().getParameters();

public CCADeleteOverrideExt(ApexPages.StandardController stdController) {

    this.cca = (CallCycleActivity__c)stdController.getRecord();

    //The return URL is passed via the custom button - get this to know where to return after a Save or Cancel
    if(URLParameters.containsKey('retURL')){
        pageRef = new PageReference(URLParameters.get('retURL'));
    }

}

public PageReference customDelete(){
    delete cca;

    // Return whatever PageReference you want here
    pageRef.setRedirect(true);
    return pageRef;       
 }

}

0

Just set the redirect to URL of the parent via parent's record id, i.e.

public PageReference customDelete(){
  PageReference ret = new PageReference('/' + cca.parent__c); //replace parent__c with appropriate relationship field
  delete cca;
  ret.setRedirect(true);
  return ret;       
}
0
0

Your customDelete pagereference should redirect to the VF page passing the parent URL again - try setting it explicitly using the parent ID instead of using the existing pageRef. Instantiate a new Ref.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.