1

I am studying it still, I am new here and have not much experience, what I am trying to do is:

  1. Trying to pass a date/time value from an input field through JavaScript to the Apex Controller; I've got this one working now, and

  2. now what's happening is, I want to call the Apex Controller so I can use the start and end dates in my query's where clause. Because the controller is being called when the app is opened, when I hit the button, my query is not being executed again, that is a way to solve that? Maybe by calling a new method in my JavaScript after the user presses the button?

2

1 Answer 1

1

Trying to pass the datetime (in the input) through the JS to the apex controller - This one is working now

I would suggest provide some more information about what have you done with the first requirement what kind of JS action invocation you did.

Update: (thanks to @sfdcfox for mentioning it Lightning Enabled tag question)

Using Lightning:

If you are looking that thing in Lightning perspective then I'm assuming you used @AuroEnabled Client-server enabled menthod to pass the Date into apex controller, Now use action.setCallback() to invoke another method and pass your parameters from JS directly via action.setParams().

see below reference on more info: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm

see more info on action.setCallback(): Use of setCallBack() in Lightning

Using Visualforce (Conventional Way):

There are various ways to invoke any second method/action on completion of other, it depends on your first action invocation type. If you want to use JS for calling action then use <apex:actionFunction>, it supports rerender attribute which will helps you to rerender the result on the page side.

if you used <apex:actionSupport> or <apex:commandLink> or <apex:commandButton> or <apex:actionFunction> as your first invocation, then you can use onCompletion attribute of these action methods, and in that oncompletion you can call any other <apex:actionFunction> which eventually calls your controller action.

see more on <apex:actionFunction> : https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_actionFunction.htm

5
  • 1
    While not a bad answer, this question was tagged lightning, so I don't think that's what the OP is looking for.
    – sfdcfox
    Jan 12, 2017 at 5:59
  • @sfdcfox, thanks for mentioning, I didn't checked that, I'm updating my answer. Jan 12, 2017 at 6:13
  • Questioner should include lightning as well in the question title, because as per this question if anyone looking for the same in VF and google it, then this question will be popup. Jan 12, 2017 at 6:15
  • You're absolutely right. I'll make a minor edit and notify the user.
    – sfdcfox
    Jan 12, 2017 at 6:17
  • Hello everyone, sorry for my delay in answering, was a bit busy and couldn't check it, thank you for all you help, my problem was solved by setting the callback(). Jan 12, 2017 at 7:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .