0 votes
1 view
in Salesforce by (11.9k points)

I know how to return a PageReference to edit and view a sObject:

PageReference ref =  new ApexPages.StandardController(bnk).edit();

But the StandardController class hasn't any method like create.

How can I return the page to create the sObject.

I also know the method like:

PageReference ref =  new PageReference('/a00/e');

but the sObject has many lookup fields. This method can't take out the reference lookup fields. It only can create a standalone sObject.

So how to return the create page and also take out the reference lookup fields?

1 Answer

0 votes
by (32.1k points)

Use the DescribeSObjectResult to get the KeyPrefix as shown below:

public PageReference customObjectPageReference() {

    Schema.DescribeSObjectResult R = YourCustomObject__c.SObjectType.getDescribe();

    // Add /o to end of URL to view recent

    return new PageReference('/' + R.getKeyPrefix() + '/e');


Welcome to Intellipaat Community. Get your technical queries answered by top developers !