0

I need to override the edit link of a relatedlist with visualforce page. The visualforce page will do nothing but redirect the user to the standard edit page of the record. I tried the following but it keeps on performing the action again and again.

<apex:page standardController="Escrow_Contact__c" extensions="PWEscrowContactController" action="{!redirectToPage}">
</apex:page>

Controller:

public class PWEscrowContactController {

private final Escrow_Contact__c contact1 {get;set;}

public PWEscrowContactController(ApexPages.StandardController stdcontroller){
  this.contact1 = (Escrow_Contact__c)stdController.getRecord();  
}

 public PageReference redirectToPage() {
     return new ApexPages.StandardController(contact1).edit();
 }

}

I need to accomplish this because I have used a relatedlist within Visualforce page and used the page in standard layout as a section and while performing edit within this Visualforce page it redirects me directly to the Visualforce page instead of redirecting me to the parent record page.

The url when edit link is clicked from standard related list layout is, https://cs13.salesforce.com/a0aW0000001S6nB/e?retURL=%2Fa01U000000eZke5

but the url when edit link is clicked from the Visualforce page section of related list layout is, https://cs13.salesforce.com/a0aW0000001S6nB/e?retURL=%2Fapex%2FvfEscrowContacts%3Finline%3D1%26id%3Da01U000000eZke5

I need to overcome this issue.

  • Ean, those links are not going to work because they are not public. – Carlos Naranjo Mar 2 '17 at 13:33
  • @Viasur How do i redirect the user to standard edit page of the record through visualforce page when they click on the edit link. – Ean Mar 2 '17 at 13:35
  • @Ean refer this – Rohit Mourya Mar 2 '17 at 13:59
  • @Rohit Mourya I have referred that link only but the problem is i am performing the action directly on the visualforce apex tag and hence i am being taken into loop. – Ean Mar 2 '17 at 14:12
1

If you want to override the Edit action for a specific object you need to go to the object and select 'Buttons, Links, and Actions'.

After that, you can override any action on that page. If you click on 'Edit' on the left side of the Edit label you will see the options for that action. Just change the 'Override with' to 'Visualforce Page' and select the page you want to use from the drop-down options.

To access the object if Standard: Setup - Build - Customize

To access the object if Custom: Setup - Create - Objects

Hope this helps.

UPDATE: It is also redundant after clicking on Edit to send the user to Edit again, that will be a loop. You are redirecting the user to the same action on your class. Basically, you are sending the user over and over to the same Edit page that is firing the Edit page.

Also consider that if you override the Edit action on the object, that will affect to all your Edit actions for that object. It will become your main Edit operation, not only for the Edit link on the view list.

And there is an </apex:apexpage> missing on your Visualforce page

  • Thanks but i already knew about this and that is what i have done now but the problem is the visualforce action method keeps on executes and hence i am always redirected to the edit page even after i click on the save or cancel button. – Ean Mar 2 '17 at 13:54
  • What is exactly what you want the user to see after clicking on the Edit link? – Carlos Naranjo Mar 2 '17 at 13:56
  • I want the user to be taken to the standard edit page of the object but the url should be specified by me due to the issue i mentioned in the post. i.e. when the user clicks on the edit link of the related list record which is within the visualforce page, the edit url includes the visualforce page name which i don't want to happen. – Ean Mar 2 '17 at 14:11
  • Ok, if you want to do that I think you should build an Edit2 Visualfroce page that it is equal to the standard SFDC one. Then edit the standard Edit action for that object, and do a partial URL in your PageReference redirecToPage method pointing to the new Edit2 Visualforce page. – Carlos Naranjo Mar 2 '17 at 14:30
  • Oh! Isn't there any way to do that with the SFDC one? – Ean Mar 2 '17 at 14:32

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.