I have a custom button on task related list of Account Object. The button contains the URL as: /apex/GetDynamoDBTasks?id={!Account.Id} Where GetDynamoDBTasks is a Visualforce page. I want to pass id dynamically in place of {!Account.Id}. I mean as it is on Account object so I used, Account.Id. If I use this button On opportunity's task related list, it should take opportunity.Id and If I use it for contact, then the Id value should be contact.Id. That means the same custom button for all objects. How can I achieve this? Any solution or idea on this.

  • 4
    nop.... you need to create different custom button for all the objects. – Ratan Paul Mar 18 '16 at 8:33
  • So you mean This is not possible right! @@sfdcweb – Sweta A Mar 18 '16 at 8:35
  • How you are using the ID that you pass in the URL of the VF page? I mean, are you using the ID to query the records? What is the functionality of the GetDynamoDBTasks VF page? – Shailesh Patil Mar 18 '16 at 8:47
  • Yes I am passing the parent object's id in the custm button's url as specified in the code. The vf page opens a task detail page by getting the id of the parent object. I mean If it is on Account object's task(Activity History) related list, it opens the latest task's detail page when clicked on the button. @ Shailesh Patil – Sweta A Mar 18 '16 at 8:53
  • @SwetaA yes it not possible. – Ratan Paul Mar 18 '16 at 9:09

It is possible. Below is my javascript code.

var recId = window.location.href.substring(window.location.href.lastIndexOf('/') + 1);
window.location = '/apex/GetDynamoDBTasks?id=' + recId;

That's it. I got my recordId there and I passed it in the URL.

Thank you.

  • This won't work in Lightning Experience, as it is a Javascript button. It is not a best-practice. – DavidSchach Jan 21 '18 at 3:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.