You need to sign in to do that
Don't have an account?
jeremiah_small
Overriding New
Hello everyone,
I have a custom object called Stacked Rebate Group (SRG), which is always created from the context of a custom object called Rebate, via the New button on the related list. There are no required fields in SRG. Two lookup fields are populated by the before trigger when the object is saved.
The before trigger automatically duplicates the Rebate two times, and associates the two new copies with the two Lookup relationship for the new Stacked Rebate Group, making a Stacked Rebate Group with three copies of the same Rebate each associated by one of three Lookup fields.
What happens using the default New behavior is the user sees the Edit layout, and the fields that should relate to the two new copies are not filled in yet. Clicking save, without filling in either of the two new records fires the before trigger, and the copies are created, and the Lookup fields are filled in, no problem.
See screen shots below.
The trouble is, I would like to make a simple VF page to override the New behavior, automatically attempting to "click Save" for the user, but I can't seem to get it to work the same way I do with the default behavior, even though I think it should be doing the same thing. Here's the simplest form of what I'm trying in the VF.
What happens when I use this page is my trigger show my custom error that says "SRG must be created from and ongoing offer," which only happens if there's no Rebate to duplicate (like if someone were allowed to just click New on the SRG object directly). This seems to point to the fact that the standard controller doesn't get the hand-off in VF the same way that it does when I enable the default New behavior. I've tried removing the Save action and adding...
...and it certainly doesn't see the New SRG, but that makes sense until it's been saved. Since it's based on the standard controller, what else would I have to do in my VF to be able to access the handed off Rebate record that is to be duplicated by the trigger.
As I mentioned, the attached pictures show what happens using the default New behavior. First the user is presented with a blank form, excepting the Ongoing Offer Rebate. Then by simply clicking Save, the trigger fills in the other two. I'd like to programmatically click save for them. Can anyone offer any suggestions here?
Jeremiah
Pictures of the default "New" behavior:
Then just click save, and this is where it ends up. I'd like to be able to skip the above step and go directly to the below state on New.
I have a custom object called Stacked Rebate Group (SRG), which is always created from the context of a custom object called Rebate, via the New button on the related list. There are no required fields in SRG. Two lookup fields are populated by the before trigger when the object is saved.
The before trigger automatically duplicates the Rebate two times, and associates the two new copies with the two Lookup relationship for the new Stacked Rebate Group, making a Stacked Rebate Group with three copies of the same Rebate each associated by one of three Lookup fields.
What happens using the default New behavior is the user sees the Edit layout, and the fields that should relate to the two new copies are not filled in yet. Clicking save, without filling in either of the two new records fires the before trigger, and the copies are created, and the Lookup fields are filled in, no problem.
See screen shots below.
The trouble is, I would like to make a simple VF page to override the New behavior, automatically attempting to "click Save" for the user, but I can't seem to get it to work the same way I do with the default behavior, even though I think it should be doing the same thing. Here's the simplest form of what I'm trying in the VF.
Code:
<apex:page standardController="SMART_Stacked_Rebate_Group__c" action="{!save}"> <apex:messages /> <apex:Detail subject="{!SMART_Stacked_Rebate_Group__c.id}"/> </apex:page>
Code:
<p>SMART_Stacked_Rebate_Group__c.id: {!SMART_Stacked_Rebate_Group__c.id}</p>
As I mentioned, the attached pictures show what happens using the default New behavior. First the user is presented with a blank form, excepting the Ongoing Offer Rebate. Then by simply clicking Save, the trigger fills in the other two. I'd like to programmatically click save for them. Can anyone offer any suggestions here?
Jeremiah
Pictures of the default "New" behavior:
Then just click save, and this is where it ends up. I'd like to be able to skip the above step and go directly to the below state on New.
using a controller extension like this:
Then by editing the Related list in the Parent object, I deselected the default New button and selected my custom New button. That did it.
The problem was populating the foreign key field in the uncommitted object. By passing the value via the url, and using a simple controller extension, it works great.
HTH
Jeremiah
Message Edited by jeremiah_small on 11-12-2008 03:26 PM