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?



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.

  • 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. May 5 '14 at 12:53

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.