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
bohemianguy100bohemianguy100 

retURL in URLFOR not redirecting correctly

I have a VF page that is embedded inline on a custom object page layout section.  In the VF page, I used a command button to redirect to another custom object using the URLFOR New Action.

 

<apex:commandButton onclick="window.parent.location.replace('{!URLFOR($Action.Design__c.New)}');" value="Add Design" rendered="{!IF(designId == null, true, false)}" />

 This works and opens the custom object in the create 'New' record mode.  However, if I click 'Cancel' the retURL opens my VF page directly and not inline on the custom object page layout, which is very bad.  I displays the VF page with no way to get back to the Salesforce UI without hitting the back button.

 

How can I set the retURL probably in the URLFOR method so when the user clicks cancel that it will redirect them back to the correct page?

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
bohemianguy100bohemianguy100

 

Found the solution:

 

{!URLFOR($Action.Design__c.New, null, [retURL=SOMEOBJECTID])}

 

Replace "SOMEOBJECTID" with the Id of the custom object record you were originally viewing.

All Answers

Jerun JoseJerun Jose

You can try to mention the retURL value explicitly.

 

<apex:commandButton onclick="window.parent.location.replace('{!URLFOR($Action.Design__c.New)}'+'&retURL=/{!Design__c.ID}');" value="Add Design" rendered="{!IF(designId == null, true, false)}" />

 Just a thought. May not work out so well.

 

bohemianguy100bohemianguy100

 

Found the solution:

 

{!URLFOR($Action.Design__c.New, null, [retURL=SOMEOBJECTID])}

 

Replace "SOMEOBJECTID" with the Id of the custom object record you were originally viewing.

This was selected as the best answer
SFDC coderSFDC coder
hi Jerun Jose,

what if i want to return back to the VF page i had come from?
In that case how do i write my returl paramter?