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
como_estascomo_estas 

Standard Edit page Redirect doesn't work

So I have a custom VF page that I wrote as an edit page for a custom object in my org.

 

<apex:page standardController="OrgEvent__c" extensions="EventEditController">

 

On this edit page, there is a button to create a new ContactScheduleItem__c, which is another custom object which has OrgEvent__c as a master detail.  Here's what the button looks like:

 

<apex:commandButton value="New Registrant" action="{!newAttendee}" rerender="attendees"/>

 

Within the EditEventController class, you guessed it, I have a method called newAttendee which is supposed to return a pagereference to a standard edit page for a new ContactScheduleItem__c:

 

	public PageReference newAttendee() {

		apexpages.pagereference ref = new apexpages.standardcontroller(new ContactScheduleItem__c()).edit();
		return ref;    	
	}

 

All looks like it should work, right?  Here's the fun part.  It doesn't.  No matter what kind of object's standard edit page I try to return in this method, It simply redirects me to an edit page for the object i'm currently viewing, which is an OrgEvent__c.

 

It's almost like since i have a standard controller in scope, i'm not allowed to create a new one in this method.  Does anybody know why I can't make this work?

como_estascomo_estas

 

An additional note...  I don't want to use the object prefix way because I need to prepopulate a field in this new contactscheduleitem__c page.  As far as I can tell, you can pre-populate a field, but you need its Id.  This code is going into a managed package so I can't do that.  The IDs are different in each org.