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
Radha Rathinavel PandianRadha Rathinavel Pandian 

Trigger to redirect the page

Hi,
My requirement was to redirect my page after the record gets saved without using VF page,
I am using Case object here. I need to send an agreement using custsom url, So Here What I needed is to redirect to the custom url when the records gets submitted. Please assist me.
 
Best Answer chosen by Radha Rathinavel Pandian
YogeshMoreYogeshMore
Hi Radha,

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();"/>

Regards,
Yogesh

All Answers

Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Radha, hope it helps.

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Thanks
Rahul Kumar
YogeshMoreYogeshMore
Hi,

You can achieve this by adding extra parameter in the URL.
Example:
When you edit or create the records, Normally your URL like this.

https://ap5.salesforce.com/0037F00000JYwIf/e?retURL=%2F0037F00000JYwIf&_CONFIRMATIONTOKEN=VmpFPSxNakF4T0Mwd01pMHdNbFF3T0RvMU1qbzBPUzQwTWpKYSxWamdWa0VFVVRyN2R5MDVJblMxZWs1LE56QmpOemN3&common.udd.actions.ActionsUtilORIG_URI=%2F0037F00000JYwIf%2Fe

As a standard way, when you click on the save button it will redirect to the record level.

But by using &saveURL= parameter you can override the standard save button redirection. Your URL will be like this

https://ap5.salesforce.com/0037F00000JYwIf/e?
retURL=%2F0037F00000JYwIf&_CONFIRMATIONTOKEN=VmpFPSxNakF4T0Mwd01pMHdNbFF3T0RvMU1qbzBPUzQwTWpKYSxWamdWa0VFVVRyN2R5MDVJblMxZWs1LE56QmpOemN3&common.udd.actions.ActionsUtilORIG_URI=%2F0037F00000JYwIf%2Fe&saveURL=001


Please mark this answer as SOLVED and BEST ANSWER if it helps you.

Regards,
Yogesh More

Salesforce consultant || Salesforce Developer
more.yogesh422@gmail.com || Skype:-yogesh.more44​
 
Radha Rathinavel PandianRadha Rathinavel Pandian
Yogesh, 

I am integrating adobe esign with my application so the custom button created to send an agreement with the hep of  below url,
/apex/echosign_dev1__AgreementTemplateProcess?masterId={!Case.Id}&templateID=a071I000002qEJN
So here What I required is to automate this link to redirect when my case object records gets saved
YogeshMoreYogeshMore
Hi Radha,

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();"/>

Regards,
Yogesh
This was selected as the best answer
Sahil Sharma 36Sahil Sharma 36
Please note that the below solution only works in Lightning. This can be done with the help of an invisible lightning component on the record page.

Component:
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    
        <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
        <aura:handler name="change" value="{!v.simpleRecord}" action="{!c.onChange}"/>
        
        <aura:attribute name="record" type="Object" />
        <aura:attribute name="simpleRecord" type="Object" />
        <aura:attribute name="recordError" type="String" />
        
        <force:recordData aura:id="recordHandler"
                          fields="IsPrivate"
                          recordId="{!v.recordId}"
                          targetError="{!v.recordError}"
                          targetRecord="{!v.record}"
                          targetFields ="{!v.simpleRecord}"/>
        
    </aura:component>

Js Controller:
onChange : function(component, event, helper) {
            console.log('on change...');
            var urlEvent = $A.get("e.force:navigateToURL");    //Redirect from here
            urlEvent.setParams({
                    "url": "/006/o"
            });
}

Go ahead and drop this component on the record page of any object. You will be redirected to the given URL in case of any change.
Please note that we can add any conditional statement in the 'onChange' function of the controller.
 
Mir Niaz 11Mir Niaz 11
Sahil,

You'll also need to add the urlEvent.fire(); command to the JsController to actually launch the link. 
I'm actually looking to have this event fire upon a field change, any ideas on how I could do that? 
The component doesn't have the ability to perform an ISCHANGED formula field, so I'm a bit lost here. 

Thank you!