+ Start a Discussion
mworld2mworld2 

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?

mikefmikef

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.

mworld2mworld2

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

 

Yup! Searching for Describe was the ticket. Thanks!