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
Luciano RobertoLuciano Roberto 

Trigger to redirect page

Hello guys,

I need to create a redirection through a trigger when updating a record. Can someone help me with some code to meet this need?

I have a visual force page that creates a record and already opens it in edit mode, but when saving it, it redirects to the visualforce page, what I need is to be redirected to the newly created (updated).

Thanks
Best Answer chosen by Luciano Roberto
Ajay K DubediAjay K Dubedi
Hi Luciano,
I think you are using Visualforce page to send the agreement and there you want to redirect the page.
So you can use following code in your class to redirect on another page.
 
public PageReference save() {
        // Add the case to the database. 
        insert case;
        // Send the user to the detail page for the new account.
        PageReference custPage = new PageReference('/URL');
        custPage .setRedirect(true);
        return custPage;
    }

OR
You can do same redirection on Visualforce page using JavaScript with OnComplete attribute of Visualforce Component.
Your JavaScript code will be like This.
 
<Script>
function redirect(){
window.open("https://www.w3schools.com","_self");
}
</Script>

And call this method from onComplete attribute. for example.
 
<apex:commandButton value="Save" action="{!save}" oncomplete="redirect();"/>

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi

All Answers

Ajay K DubediAjay K Dubedi
Hi Luciano,
I think you are using Visualforce page to send the agreement and there you want to redirect the page.
So you can use following code in your class to redirect on another page.
 
public PageReference save() {
        // Add the case to the database. 
        insert case;
        // Send the user to the detail page for the new account.
        PageReference custPage = new PageReference('/URL');
        custPage .setRedirect(true);
        return custPage;
    }

OR
You can do same redirection on Visualforce page using JavaScript with OnComplete attribute of Visualforce Component.
Your JavaScript code will be like This.
 
<Script>
function redirect(){
window.open("https://www.w3schools.com","_self");
}
</Script>

And call this method from onComplete attribute. for example.
 
<apex:commandButton value="Save" action="{!save}" oncomplete="redirect();"/>

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
This was selected as the best answer
Luciano RobertoLuciano Roberto
Hi Ajay thanks for your help. Working!