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
BARBAR 

Custom button -- how to include return URL

I have created a custom button that calls a VF page 'CreateClasses' -->  /apex/CreateClasses?id={!Campaign.Id}

This button resides on the page for a particular Campaign record type.  When I select the Cancel button on the CreateClasses page, I want to return to this same page. 

 

How can I include the retURL parameters in the custom button (without hard-coding the entire URL)?  Is there any way to capture the $CurrentPage.Name from the original/calling page?

 

Thanks,

Barb Ryan

Best Answer chosen by Admin (Salesforce Developers) 
BARBAR

I actually found another solution that worked --- it was written by Wes as follows:

 


 

Hey

 

Try this,

 

public String aId = apexpages.currentpage().getParameters().get('id'); 

 

 public PageReference
cancel() {

//cancel method to return to the account
detail page
return new PageReference('/'+aId);
}

 

The return new
ApexPages.StandardController(acct).view(); call can only be used from
within a standard controller extension.

 

Wes 

All Answers

Ispita_NavatarIspita_Navatar

On the Cancel button you must be calling some function try the following :-


PageReference pageRef = new PageReference('<partialURL>');

Set partialURL to '/' + <recordID>
Here <recordID>= newOpp.id;

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

WesNolte__cWesNolte__c

Hey

 

Make your custom button hit this URL instead,

 

/apex/CreateClass?id{!Campaign.id}&retUrl={!$CurrentPage.Url}

 

And on the 'CreateClass' page put the following in your cancel button,

 

{!$CurrentPage.parameters.retUrl}

 

Cheers,

Wes

BARBAR

I actually found another solution that worked --- it was written by Wes as follows:

 


 

Hey

 

Try this,

 

public String aId = apexpages.currentpage().getParameters().get('id'); 

 

 public PageReference
cancel() {

//cancel method to return to the account
detail page
return new PageReference('/'+aId);
}

 

The return new
ApexPages.StandardController(acct).view(); call can only be used from
within a standard controller extension.

 

Wes 

This was selected as the best answer
tggagnetggagne

If your button is Javascript, you should be able to use..

 

encodeURIComponent(window.location.href);