We have a managed package that contains a custom button. This button currently sits on the Campaign's standard page layout. We would like to check that all the Campaign members meet certain criteria before the javascript of the managed package's custom button executes.

I'm not sure how to approach this, and I didn't want to copy and paste the managed code to my own custom button. Is it possible to execute the code of the managed package's custom button from a different custom button?

  • 1
    You might be able to replace the custom button with your own if the method being called inside of the managed package was global.
    – greenstork
    Jun 9, 2014 at 19:39
  • can you see the code for the javascript in the managed package's custom button? Jun 10, 2014 at 4:39

1 Answer 1


With a little bit of dev work you should be able to build a custom button that evaluates your criteria and if it passes calls the managed package button.

You could place the logic in javascript with a custom button, or create a visualforce page that is tied to a custom button with an apex controller to evaluate your entry criteria.

If it passes you'll want to use URLFOR to call the managed package button with the campaign id. E.g. {!URLFOR($Action.Campaign.Button_Name,Campaign.Id)}. If it doesn't you'll want to provide some feedback to the end user about why the button didn't process.

Example JS

var goodToGo = true;
// logic to determine if it's good to go
if(goodToGo) {
  window.location.href = '{!URLFOR($Action.Account.APXTConga4__Conga_Mail_Merge,Account.Id)}'
} else {
  alert('Not ready to go');

Example Button

enter image description here

  • I can see the JavaScript code in the Managed Package's custom button. I'm creating my own custom button that will execute javascript to perform checks using SF's Ajax Toolkit. Can you give an example of how I would use "{!URLFOR($Action.Campaign.Button_Name,Campaign.Id)}" in a JS command? It's not doing anything when I use it by itself. Jun 10, 2014 at 19:47
  • yep, that returns the URL, it doesn't do anything else, you'd need to change the window location with it, e.g. window.top.location.href = '{!URLFOR(...)}';. If you're doing this you should either (A) be comfortable with JS, (B) be okay with a lot of trial and error and head scratching when you're stuff works fine in one browser but not another. Jun 10, 2014 at 22:20
  • Using the window.top.location.href does not seem to allow access to the JS code of the button. The result is a page with the error 'URL No Longer Exists'. I've tried manipulating the returned URL to see if there's a URL format issue, but that hasn't brought in the JS either. Jun 11, 2014 at 14:45
  • you don't need to bring in the JS, just execute yours then refer the page to their button which will cause their js to get executed, i've updated the answer Jun 11, 2014 at 18:00
  • idea is that if there js changes you don't have to update your code, in essence you need to think of their button as a black box, you don't know what's inside, you just know that if certain conditions are met you open the black box, otherwise you tell the user you aren't opening the box Jun 11, 2014 at 18:01

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.