You need to sign in to do that
Don't have an account?
AussieBattler
Redirect from a Trigger
Hi,
I want to redirect a user to a custom object if certain conditions are met.
So to that end, I have a trigger that is set off after a record is inserted or updated and this trigger calls a function in a class that handles the redirection. Everything works, all the code in the trigger and class is executing as I would expect, but instead of redirecting the user to the new screen it returns them to the newly saved record (as it would normally behave).
Any ideas where I am going wrong?
Trigger Code:
Class Code:
I want to redirect a user to a custom object if certain conditions are met.
So to that end, I have a trigger that is set off after a record is inserted or updated and this trigger calls a function in a class that handles the redirection. Everything works, all the code in the trigger and class is executing as I would expect, but instead of redirecting the user to the new screen it returns them to the newly saved record (as it would normally behave).
Any ideas where I am going wrong?
Trigger Code:
Code:
trigger testTrigger on Object__c (after insert,after update) { Object__c[] obj = trigger.new; if (obj[0].Picklist__c == 'Change') { String objId = obj[0].uniqueID__c; redirectClass.redirectFn(objId); } }
Class Code:
Code:
public class redirectClass{ public static PageReference redirectFn(string uID) { Test__c sID = [SELECT Id FROM Test__c WHERE uID__c =:uID LIMIT 1]; string currURL = '/' + sID.Id; PageReference redirect2 = new PageReference(currURL); redirect2.setRedirect(true); return redirect2; } }
it's true they can block a save by using addError(), but the trigger is not controlling how the page will handle that, the browser is.
if you called that code from a Visualforce page (controller) it would work.
Some combo of apex trigger and s-control - Any clue how it is possible to do?