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
sean*harrisonsean*harrison 

Overriding the New button without disrupting flow


Scenario: When creating a new Event need to copy the content of a field in the related Contact record and place into a field in the Event. That info can than be further modified while on the Edit page.

Challenge: There are two page layouts for the Edit page of the Event object. We don't want to interrupt the establish flow of steps, just make the change to the brand new Event record and display the standard Edit page.

Being new I'm not sure of the best approach. I assume I should, in theory, do the following:

1. Create a controller extension
2. Create a VF page referencing the extension
3. Use an action attribute in apex:page to return the default page reference
4. Override the New button

button will fire page,
extension attribute will fire extension methods,
action attribute will fire the next step in the normal flow of steps.

Am I on the right track?

or should I be using a Trigger? Does the "before insert" event occur between the time the New button is clicked and the Edit page appears? I would assume not...


Thanks! S

Pradeep_NavatarPradeep_Navatar

Can you please clarify whether you have two page layouts or Record types?

sean*harrisonsean*harrison

Both. When creating a new Event, the user is presented with a choice of Record Type (distinct for each of two business units). The detail page has two Page layouts (again distinct for each business unit).  Does that help?

Pradeep_NavatarPradeep_Navatar

Then you can go for a Trigger. Try this logic

 

trigger myTest on Event(before insert)

{

                if(Trigger.isBefore)

                {

                                for(Event evt:Trigger.new)

                                {

                                                //field value from Contact

                                                if(evt.WhoId != null)

                                                {

                                                                String strValue=[select c.myField from Contact c where c.id= :evt.WhoId].myField;

 

                                                                evt.fieldXYZ=strValue;

                                                }

                                }

 

                }

}

 

Did this answer your question? If so, please mark it solved.

sean*harrisonsean*harrison

I'm coming back to this after the fact but there is no way without using a Trigger.  What I really wanted was some way to make the change at the point the New Event was selected so that the user, when filling out the form, would see the change at this point. With a trigger the modification doesn't happen until they are done and have clicked "Save."

 

Andres Perez with Salesforce suggested that it would be possible to rebuild the New Event page from scratch but that seemed a rather large task for such a small change. My users were good with the trigger once I demoed it.