Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a managed-package VF page that has a button which calls the page controller's method. While i can go to the page and click that button to invoke managed code, I would like to invoke it programmaticaly from my trigger.

Is there a way to do that? Maybe by simulating the page load and a button click usiing apex?


share|improve this question
up vote 4 down vote accepted

It very much depends on whether the author of the managed package intended the method to be called in this manner. If the page controller exposes the action behind the button globally, there may be a good chance that you can. Of course, there maybe other variables on the page and/or controller itself that might be required to make that method call successful. Sometimes the author of a managed package will provide an API so that consumers can call managed functionality.

The key thing though, will be the accessibility of the controller methods which you can see by viewing the class in Develop->Apex Classes and seeing which methods are public vs global. If the method you want to call is not global, you will be out of luck.

As per your idea, you could obtain the content of the page by calling the getContent() method on a PageReference instance (thus simulating the page 'load'), but there would be no way to simulate the button click from server side Apex.

share|improve this answer
Very well. I started down the PageReference.getContent() path, but then got stuck and didn't know what I could do after that. Thanks for the answer. – Kirill Yunussov May 5 '14 at 12:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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