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
Eyal_WizEyal_Wiz 

Redirect user to a certain URL

Hi all,
 
Is there any way to redirect the user to another URL once a record is updated?
 
I've created a new custom object, i've a "after update" trigger for this custom object and in this trigger i'm trying to redirect the user to another location if a certain condition that i defined is happening.
 
I would really appriciate any lead or idea for solving this as i really need a solution for this real quick.
 
Thanks alot
Eyal
magdamagda
Hi,

Maybe can this code help you


Code:
PageReference opptyPage = new PageReference('/' +
newObject.id);
opptyPage.setRedirect(true);
return opptyPage;

Magda

Eyal_WizEyal_Wiz
thanks alot for your quick answer.
 
I tried using the code you gave me inside the trigger and i'm getting this error message when i'm trying to save the trigger:
 
"Compile Error: Trigger return cannot specify a value"
 
any suggestions?
 
Thanks
Eyal
magdamagda
o,

i used that in my class and not in a trigger...

I'm sorry.

If i find a solution i come back to you.

Did you read the apex code guide? Perhaps can you find eneything in this on?

Magda
Eyal_WizEyal_Wiz
I've read it all like 10 times and still couldn't find a solution for that one.
 
Do you if there a way to call functions that i defind in a class inside a trigger?
 
Thanks alot
Eyal
magdamagda

Code:
trigger xx on Object__c (before insert) {
Object__c object[] = trigger.new;
Class.Function();
}

Hi,
you have only to write class.function in your trigger.
Like in this code example

I hope that can help you

Magda
 
Eyal_WizEyal_Wiz

It didn't work but thanks alot for all quick responses - I really appricate it!

Eyal

magdamagda
your welcome.

Why is that not running?
In my application it is running...

Maybe has another Person a better solution....

Good Lock by programming

Magda
Eyal_WizEyal_Wiz

The class is defind that way:

public class ClassTry {

public pageReference googlere() {
   
   PageReference acctPage = new PageReference('http://www.google.com');
   acctPage.setRedirect(true);

   
   return acctPage;
}

}
 
The Trigger is defind that way:
 
trigger try on Class_Registration__c (after insert) {

ClassTry.googlere();

}
 
I'm gettig the following error msg:
Compile Error: Method does not exist or incorrect signature: ClassTry.googlere() at line 3 column 1
 
p.s
I'm really sorry that i've alot of questions, i just got to have this thing working!
 
Thanks
Eyal
magdamagda
Hi,

my mind it is a lack in your trriger or class.
Maybe can the Chapter 8 Paragraph Trigger in salesforce_apex_language_reference.pdf can help you.

magda
bjohnsonbjohnson
You need to change the signature on your method In ClassTry.

From:
public pageReference

To:
public static pageReference

If you want to use a method without creating an instance(Objectx o = new Objectx()), you need to make that method static. Your method would have worked if you declared and instantiated it first. You could even do it anonomously((new ClassTry()).
googlere()). Since you would be using this method like that it is a good sign it would be better as a static method.



R TyeR Tye
Hello, is it possible to perform this action with a standard object?  I would like to build this action into the 'Case' object.  If a flag is checked the page will redirect to a new Task page. 
I've implemented the below code, but upon clicking save (on 'after update') the page will just return the the original case object as
if no trigger was fired.

trigger TEST_TaskCreator_TGR on Case (after update) {

  for(  Case Tnew:trigger.new){
   if(Tnew.Create_Task__c == True){
    TaskCreate.taskpage();
   }
  }
}

---------------------------------------------------------------------------------

public class TaskCreate {

public static pageReference taskpage() {
  
   PageReference changePage = new PageReference('https://na5.salesforce.com/00T/e');
   changePage.setRedirect(true);
  
   return changePage;
}

}


Message Edited by R Tye on 07-27-2008 10:59 PM