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
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!