You need to sign in to do that
Don't have an account?
Sapn Thakur
Set Redirect
Hi All,
We are having one custom object called 'XXX'. We are creating new XXX object record depending on certain conditions when we update opportunity using trigger.
When we create custom object record on updating of Opportunity, we want to redirect the page to the new custom object record not to the Opportunity.
Please let me know how we can do this.
Thanks,
Sapna
Sapna,
If I am right you are creating the custom object 'xxx' record through a trigger which will happen on Save.
To redirect to the detail page of 'xxx' record you have to write an controller extension for opportunity where you can perform both creating xxx record and redirect to custom object detail page.
xxx record = new xxx();
insert record;
pagereference detail = new pagereference('/'+record.id);
return detail;
its not possible to return or using the page reference in the trigger instance....
Sapn,
You cannot achieve the page-redirection functionality you're looking for through Apex triggers, because triggers have no control over the User Interface. The best way to achieve what you are looking for is by having your Opportunity Edit page be a Visualforce page and overriding the Save action. You can leave your business logic in the trigger code if you want it to be enforced on ALL Opportunity updates, but if you only want it to be enforced on Opportunity updates that occur through the UI, then it probably makes more sense to remove it from the Trigger.
FIrst, you will need to create a controller extension for Opportunity (as Cloud Nine has said), with a page action method to call instead of the standard controller's save() method. We will just call this save(). Your custom logic---which will create a new XXX record if certain conditions on the Opportunity record are met---could go here if you ONLY want it to be enforced on Opportunity updates that occur through the UI.
You will then need to override the Opportunity object's Edit action with something like the following page:
Hey thanks all for the reply.
I don't want to create visualforce page for the edit opportunity and override the save action. I wanted this to be achieved using apex trigger only but that is not possible.. :(