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

Redirect from a Trigger


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:
trigger testTrigger on Object__c (after insert,after update) {

Object__c[] obj =;
if (obj[0].Picklist__c == 'Change') {
String objId = obj[0].uniqueID__c;

Class 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);
 return redirect2;    



Ron HessRon Hess
triggers are not connected to the browser in any way at all, they may fire when an API call is run for example.

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.
I've seen redirect happen after trigger in some Appexchange app.

Some combo of apex trigger and s-control - Any clue how it is possible to do?