Thursday, March 19, 2015

Configure Redirect URLs after Record Saved in Salesforce

In general, after a record is saved in Salesforce, it will redirect to Detail Screen or list of records of its corresponding Object.

There are many cases where we want to override this functionality. For example, after a new Account created, we want user to create Tasks to it, so once the New Account is saved, page should redirect to New Task screen with Current Account ID details.

To accomplish this, we in general need to create a Custom New Form for Account and in that form, we override default save action and once default save action is accomplished, we redirect using PageReference

We also save one more easy way to accomplish this on default forms, adding details through URL parameters.

By default, Salesforce provided 3 URL parameters,  'retURL', 'saveURL', 'cancelURL'.

We can make use of these parameters to redirect the screen after default button actions.

lets understand with below simple example.

https://demo.salesforce.com/a08/e?retURL=%2Fa08%2Fo&saveURL=/apex/google&cancelURL=/apex/yahoo

The above URL is actually a new form for a custom object.

https://demo.salesforce.com/a08/e

But we also provided other parameters along with URL.

saveURL=/apex/google, this parameter is used for redirection after the record saved. So, once a record is saved, it redirected to a custom page 'google', also the newly created record Id is sent as a parameter by default.

https://demo.salesforce.com/apex/google?newid=a08o0000006rTSR

cancelURL=/apex/yahoo, this parameter is used for redirection if user clicked on default Cancel button . This redirects to a custom page 'yahoo' if user cancelled the form.

1 comment: