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
RajaMohanRajaMohan 

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.

 

Thanks

Raj

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');

empPgRef.setRedirect(true);

return empPgRef;

CodeFinderCodeFinder

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);
    createAccountVF.setRedirect(true);
    return createAccountVF;
}
}

 This is what I understood by your question.

 

For the later part of the question check this 

 

http://raydehler.com/cloud/clod/salesforce-url-hacking-to-prepopulate-fields-on-a-standard-page-layout.html

 

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