+ Start a Discussion

Navigation to custom object List page

I feel like a dunce but... I have places in my APEX code where I want to navigate to the list page for one of my custom objects. I had been using a hard coded value like '/a0I' which is the id 'prefix' for that object but I have seen that id prefixes can and do change when deployed to a new environment. How do I get at what this is in the particular environment that i am in?


Thanks in advance?


sObject Describe is what you need, I think.


That is if the object is the same name in each environment. Read the Apex docs on sObject Describe, there is a method for getting the prefix and whatever attribute you want from the object.


    public PageReference RedirectMyObject(){
        String prefix = MyObject.SObjectType.getDescribe().getKeyPrefix();
        return Redirect(prefix);


Yup! Searching for Describe was the ticket. Thanks!