[SalesForce] Using a CommandButton/CommandLink to Open a New Tab/Window

I'm looking to use either a CommandButton or a CommandLink to open a new tab or window. This is largely a problem because the URL is somewhat dynamic.

Effectively I have a list with checkboxes, the user will select some records which they need which should open up another tab containing the URL and Ids selected. It looks a bit like this:

String redirect = URL.getSalesforceBaseUrl().toExternalForm() + '/apex/AnotherApplication?firstcontact=' + firstContact + '&queue=' + queue;

PageReference pageRef = new PageReference(redirect);

return pageRef;

This produces a URL like below depending on what's been selected:

www.salesforce.com/apex/AnotherApplication?firstcontact=003ABC123&queue=003DEF456,003GHI789

I'm fairly sure I can't use CommandButtons to do this, and when I use a CommandLink, using the parameter…

target="_blank"

… Is ignored.

Is there any way around this or am I SOOL?

Thanks!

Edit
I should clarify I understand there are similar questions out there, but those seems to only point to a specific address as opposed to a dynamically generated one.

Best Answer

for this you can use Javascript. in window.open give target blank and pass your URL in method.

<script>
function openpage () {
   window.open(URL, '_target');
}
</script>

and call this method onComplete. It will solve your problem. Rerender the Script in outputpanel.

Related Topic