You need to sign in to do that
Don't have an account?

Cannot invoke new detail page from Master-detail VisualForce page
I have a Visualforce page that allows users to view the Master-detail in one UI. The page uses the Master StandardController with an Extension which allows updates/delete to the detail records.
Try as I might, I cannot get the "Add new Detail" button to invoke the Edit page for a new detail item (see Apex code excerpt below). Whatever I seem to do, it always invokes the "edit" of the Master record.
// Invoked when user presses "newDetail" button from VF page
public PageReference newDetail()
{
Detail__c newDetail = new Detail__c(Master__c=getMaster().ID);
PageReference newDetailPage = new ApexPages.StandardController(newDetail).edit();
newDetailPage.setRedirect(true);
Return newDetailPage;
}
NB: I am trying to pre-populate the master record's ID -- I want this to work as if the user pressed the "New" button on the standard Salesforce related list page
Sorry - my mistake.
Returning to the detail page after a Save is standard behaviour.
The retURL parameter has no bearing on the result of the Save action.
All Answers
I would suggest you instantiate a PageReference object and return that.
Basically the PageReference should duplicate the url (including the query string) that results when you click on the standard New button from the related list of the Master detail page.
When you look at the query string you should see two parameters prefixed with CF. The string of characters that follows CF is the Salesforce Id of the Master__c field.
Unfortunately this id cannot be obtained programmatically in Apex. You can obtain it from the url that results when you click the New button (as previously stated) or from the url when you view the detail page of the Master__c field itself.
In essence, you must hard-code this field id. The good news is that the Id will be the same across all instances for a given org (i.e. the sandbox value will be the same as in production).
Your resulting code should look something like the following:
Note that it is good practice to also specify the retURL in the query string so that the user is returned to the previous page after clicking Cancel.
Hope this helps.
Thanks, this works fine after I manipulated the return URL.
Just one minor point on the return URL. It worked perfectly for CANCEL but not for SAVE which returned me to back to the view of the standard detail page.
Any ideas?
Sorry - my mistake.
Returning to the detail page after a Save is standard behaviour.
The retURL parameter has no bearing on the result of the Save action.
Great - thanks for the help