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
sf consultant.ax380sf consultant.ax380 

Simulating a custom button / link in a VF Page?

Hey guys, VF Newbie trying to figure out best approach.

Currently... on my case layout I have a custom link which calls an custom S-Control with the behavior
of Display in new window (ie.. popup) This s-control simply builds a bunch of querystring parms and changes the window's location to an external app passing these parms and then I'm good.

I have built a new VF page and I want to add the same functionality that custom link is providing on that standard case page.

Is there a way in VF to.............
1. reference this custom link and "drop it" on the page so as I can reuse all the existing code. (I don't think so)
2. maybe utilize a commandLink (I don't need a server side action called)  and then in the onclick of the command link somehow tell it to utilize the existing custom s-control and popup a new window with specific height / width.. etc.???

The more I think about this the more I know I'm thinking about this all wrong!!! :)

Any help would be appreciated!!

Thanks



Best Answer chosen by Admin (Salesforce Developers) 
ptepperptepper
I had to do this recently and came up with a semi-hackish solution.

After someone else at my organization made a custom button, I opened the button detail and it included something like this:

Behavior:  Display in new window
Display Type: Detail Page Link
Button or Link URL: https://na5.salesforce.com/00O70000002FKsL?pv0={!myObject__c.Id}

To get a button that looks and works the same I used this HTML trick, including using the salesforce CSS class 'btn' to get the styling right.

Code:
<form>
    <input type="button" class="btn" value="My Custom Button"
       onclick="window.location.href='https://na5.salesforce.com/00O70000002FKsL—pv0={!object.id}'" />
</form>

Of course, you could just use a regular link - a href - it will do the same thing - but this makes it look like a custom button.

I stuck it inside an apex pageBlockButtons section to make it go where I wanted. You just need to make sure you have access to the object id (where it says !object.id) through the controller or otherwise. I get it from a SOQL query in the controller.

Dunno if you have the same kind of custom button but this is one way to go.

-paul


Message Edited by ptepper on 09-11-2008 01:17 PM

All Answers

devNut!devNut!
Perhaps you can use the onclick property of the commandButton and call some javascript defined on your visualforce page to perform the redirection.
ptepperptepper
I had to do this recently and came up with a semi-hackish solution.

After someone else at my organization made a custom button, I opened the button detail and it included something like this:

Behavior:  Display in new window
Display Type: Detail Page Link
Button or Link URL: https://na5.salesforce.com/00O70000002FKsL?pv0={!myObject__c.Id}

To get a button that looks and works the same I used this HTML trick, including using the salesforce CSS class 'btn' to get the styling right.

Code:
<form>
    <input type="button" class="btn" value="My Custom Button"
       onclick="window.location.href='https://na5.salesforce.com/00O70000002FKsL—pv0={!object.id}'" />
</form>

Of course, you could just use a regular link - a href - it will do the same thing - but this makes it look like a custom button.

I stuck it inside an apex pageBlockButtons section to make it go where I wanted. You just need to make sure you have access to the object id (where it says !object.id) through the controller or otherwise. I get it from a SOQL query in the controller.

Dunno if you have the same kind of custom button but this is one way to go.

-paul


Message Edited by ptepper on 09-11-2008 01:17 PM
This was selected as the best answer
Scott.MScott.M
Seems like a bit of an oversight not to include a visualforce component to include custom buttons defined in the declaritive interface. The crazy thing is that the <apex:detail> component displays those buttons.