Apex Class:
public class AccountExtensionController { public String redirectUrl {get; set;} public Boolean isRedirect {get; set;} private Account acc {get; set;} public AccountExtensionController(ApexPages.StandardController sc) { this.acc = (Account)sc.getRecord(); } public PageReference redirectToNewContact() { isRedirect = true; redirectUrl = '/003/e?retURL=' + acc.Id + '&accid=' + acc.Id; return null; } }
Visualforce Page:
<apex:page standardController="Account" extensions="AccountExtensionController" showHeader="false" sidebar="false"> <apex:form > <apex:commandButton value="New Contact" action="{!redirectToNewContact}" rerender="redirectPanel" /> <apex:outputPanel id="redirectPanel" > <apex:outputPanel rendered="{!isRedirect}"> <!--redirect using javascript--> <script type="text/javascript"> window.top.location.href = '{!redirectUrl}'; </script> </apex:outputPanel> </apex:outputPanel> </apex:form> </apex:page>