enter image description hereI have added an vf page in layout which contains Edit/Delete links.

<apex:column HeaderValue="Action">
                        <apex:commandLink value="Edit" action="{!editAccountContactRole}" ><apex:param value="{!acr.id}" name="acrId"/>
                        <apex:commandLink value="Del" action="{!delAccountContactRole}" onclick="return deleteAccountContactRole();"><apex:param value="{!acr.id}" name="acrId"/>

 //redirects to Account Contact Role Edit Page
public pageReference editAccountContactRole() {
    String configId = Apexpages.currentpage().getParameters().get('acrId');
    String trimedConfigID = configId.subString(0, configId.length() - 3);
    system.debug('****' + trimedConfigID);
    string url1 = ApexPages.currentPage().getUrl();
    System.debug('*url*' + url1);
    pageReference pageRef = new pageReference(URL.getSalesforceBaseUrl().toExternalForm() + '/' + contactId + '/e?retURL=' + url1);
    System.debug('*pageRef*' + pageRef);
    return pageRef;
} //End of editAccountContactRole() 

//Deletes account contact role record after user clicks "Del" button
public PageReference delAccountContactRole() {
    String acrId = Apexpages.currentpage().getParameters().get('acrId');
    system.debug('##acrId '+acrId );
    AccountContactRole accountContactRoleList = [select Id from AccountContactRole where id = : acrId limit 1];
    delete accountContactRoleList ;
    String baseUrl=URL.getSalesforceBaseUrl().toExternalForm();
    PageReference redirectPage=new PageReference(baseUrl+'/'+contactId);
    return redirectPage; 
} //End of delAccountContactRole() 

My problem is when i click on edit or delete button the new page is displayed in the same section i.e. the section in which i have added the page.

How to redirect them to edit page or delete page.

3 Answers 3


update your code in following way it should work. setredirect will redirect to different page.

PageReference redirectPage=new PageReference(baseUrl+'/'+contactId);
  • setredirect(true); has also not helped Nov 10, 2015 at 8:38

Here is something you can do. You have to tell your parent page to change the URL, so you will need JS to do that. Instead of returning the PageReference, return null and have the new URL saved in a variable in the class.

    public String url{get;set;}
    public Boolean flag{get;set;} //initialize this flag to false in your constructor
    public pageReference editAccountContactRole() {
    //your code
    url = URL.getSalesforceBaseUrl().toExternalForm() + '/' + contactId + '/e?retURL=' + url1;
    flag = true;
    return null;

Now in your VF page, add this code.

<apex:outputPanel id="redirect">
<apex:outputText rendered="{!flag}">
    <script type="text/javascript">
         window.top.location.href = '{!url}';

And lastly, modify your link to have a rerender attribute.

<apex:commandLink value="My Link" action="{!myMethod}" rerender="redirect"/>

Done by using target property of apex:commandLink.

<apex:commandLink value="Edit" action="{!editAccountContactRole}" target = "_parent" ><apex:param value="{!acr.id}" name="acrId"/> </apex:commandLink>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .