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
Ricardo Aguilar 4Ricardo Aguilar 4 

Redirect edit button to visualforce page

Hello,
I need to redirect the edit button to a VF page, based on a custom object record type.

Following a similar case on the forum, I created a VF page to override the standard Edit button, but I am receiving the following error.

VF Code:

<apex:page> standardController="ADELTESurvey__c" action="{!URLFOR (ADELTESurvey__c (ADELTESurvey__c.RecordType.Name, 'Delvery', $Action.ADELTESurvey__c.Edit, ADELTESurvey__c.Id, [id=ADELTESurvey__c.Id], true))}" >
<apex:variable value="{ADELTESurvey__c.RecordType.Name}" var="recTypeName"/>
<apex:pageMessages escape="false"/>
</apex:page>

Error Message:
Error: Unknown property 'ADELTESurvey__c.RecordType.Name' referenced in Survey_Edit_Redirect

It should be noted that "ADELTESurvey__c" is the custom object.

Any help would be appreciated,
Regards,
 
Deepali KulshresthaDeepali Kulshrestha
Hi Ricardo,

I have done the same with the Custom Object in my Org.
Please refer to the following code as it may be helpful in solving your problem:
VF Page:
<apex:page standardController="Content__c" extensions="ContentNewController" action="{!pageredir}" 

tabStyle="Content__tab">
  <!-- Begin Default Content REMOVE THIS -->
  <h1>Congratulations</h1>
  This is your new Page
  <!-- End Default Content REMOVE THIS -->
</apex:page>

Controller:
public class ContentNewController {
  public String var {get;set;}

  public ContentNewController (ApexPages.StandardController controller){ }
    public Pagereference pageredir()
    {

        var= ApexPages.currentPage().getParameters().get('Id'); 
        if(var!=null)
            {
            Pagereference newpage = new Pagereference ('/apex/ContentEntryPage?'+var+'&action=edit');
            return newpage;
            }
        else
            {
            Pagereference newpage =Page.ContentEntryPage; 
            return newpage;
            }
        }


In order to call it by the Standard Button you can overwrite the button as follows:
1.Go to setup -> Content__c-> Buttons,links, and actions, then click edit on new action.
2. Next select override with the visualforce option and select the created VF page you created above and save your changes. 

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
Ricardo Aguilar 4Ricardo Aguilar 4
Hello!
This code works for one record type.
The thing I miss in this code, is that we have 2 different record types. The edit button should redirect to the Visualforce Page depending on the record type.
Record Type 1 - Visualforce Page 1
Record Type 2 - Visualforce Page 2  
Thank you