Pages

Tuesday, September 23, 2008

How add a detail button to your Objects?

Let's imagine that we have a VF page which receive two address URL parameters (From and T0) and show us the driving direction from the "from" address to the "to" address.

Using the page we want to add a detail button to Sales Force Account object called "Driving Direction" and once the Sales Rep click on this button can actually view the driving directions from his office to the client's (Account's) location.

Neat, ha?

So, this is how we go about and do this:

  1. Go to "Setup" page (link located on the top right corner of the page)
  2. Under the "App Setup" expand the "Customize" item
  3. Find Account object and expand it
  4. Click on "Buttons and Links"
  5. On the "Custom Links and Buttons" section click on "New"
  6. Enter Label, Name, Description and Select "Detail Page Button" as type
  7. Behavior="Display in new Window" and Content source="URL"
  8. Let's imagine that your VF page name is "MapDirections". Then enter the following code into content of the button:



/apex/MapDirections?to={!Account.BillingPostalCode},{!Account.BillingState},{!Account.BillingCountry}&from={!$User.PostalCode},{!$User.State},{!$User.Country}

The above text includes a combination of a URL text and a few tags which later on will be replaced with actual data.

Generally tags follow this format: {!field-name} . You can easily see what field types and field names are available to you using the two dropdown lists provided by Sales Force.

And with this we are done with creating the Detail button however we won't be able to see it on the Account's detail page before we add it into the Account's Layout.

In order to add the button to the Account's layout:
  1. Go to: Customize -> Accounts --> Page Layouts
  2. Edit any or all page layout on which the Custom Button should be visible
  3. Once you click on "Edit" layout button you can view the Account's layout page
  4. On the "Button Section" double click on "Detail Buttons"
  5. A new window opens up, look at the "Custom Buttons" section your button must be listed there.
  6. Add the button to the "Selected Buttons" list and click on.
  7. Save the Layout and now you will be able to see your button as it is depicted below:

2 comments:

  1. Hi Sam, I tried your example and I am getting error message: Page Map_Directions does not exist. Map_Directions is S-Controll name. I am using clone enviroment, could this be the reason?

    Many Thanks
    Jan

    ReplyDelete
  2. Hello,

    Post really useful!

    How I can get all parameters
    {!Account.BillingPostalCode},{!Account.BillingState},{!Account.BillingCountry}&from={!$User.PostalCode},{!$User.State},{!$User.Country}

    in my visualpage?

    Can you please give guideline?

    Thanks

    ReplyDelete