+ Start a Discussion

How to navigate to the edit page dynamically?

Hi Folks,


From the controller, I need to navigate to the Employee page dynamically by clicking a 'New Employee' button.


I can hardcode like '/a0F/', but i need this to happen dynamically since I am going to create a managed package the key prefix can vary.


Also, I like to populate some of the custom filed values from the controller. How to get the field ID's dynamically for the same.


If you provide some useful information then it will be more helpful. If possible, give me some code examples.




Ritesh AswaneyRitesh Aswaney

You can get the key prefix by using the describe method

Assuming Employee is a Custom Object you've created - 

String prefix  = Employee__c.sObjectType.getDescribe().getKeyPrefix();

PageReference empPgRef = new PageReference('/' + prefix + '/e');


return empPgRef;


Can you be more clear about your question? How can you Navigate from the controller? You can navigate from one VF page to another VF page.


Well if you want 


Check this code to navigate to an id. Hope this will be of some use. 


public with sharing class ABC{

public String AcctID {get;set;}

public ABC(ApexPages.StandardController controller){

account= (Account)controller.getRecord();
this.AcctID = account.Id;
public Pagereference createAccount(){
    Pagereference createAccountVF= new Pagereference('/' + AcctID);
    return createAccountVF;

 This is what I understood by your question.


For the later part of the question check this 




This link has informaton on how to get the field ID's.