I have multiple Record Types for contact. when the user clicks on 'New Contact' button for a specific record type it should redirect to a custom edit vf page. All the remaining record types should use the standard layouts as per the assignment.
Here are my questions:
- Do I need to override the New button with the vf page? If I'm doing this overriding of button the vf page is showing to all record types irrespectively.
- Is something that I can handle in the redirect method without overriding the new method?
- Can we do it by querying the recordtype sobject instead of hardcoding?
Here is my code:
Page:
<apex:page standardcontroller="Contact" extensions="CustomEditPageController" sidebar="false" tabstyle="Contact" action="{!redirect}">
Controller:
public pagereference Redirect()
{
If(ApexPages.currentPage().getParameters().get('RecordType') != '016s00000005g78j')
{
String hostname = ApexPages.currentPage().getHeaders().get('Host');
String Contact = 'https://'+hostname+'/'+'/003/e?nooverride=1';
pagereference pageref = new pagereference(Contact);
pageref.setredirect(true);
return pageref;
}
else
return null;
}
save_new_url
param can be to a VF page with a page action method that does the redirect for you. Note that this is URL hacking and hence will not work in Lightning