1

I have written a Visualforce page to contain a button.

<apex:commandButton action="{!resendEmailsToPatients({!Disease__c.Id})}" value="Resend Email" style Class="options"/>

In my Visualforce page controller, I have:

public void resendEmails (Disease__c dis) {
  Disease__c d = dis;
  Handler.sendPatientNotification(dis);
}

So the above calls a method "sendPatientNotification(dis)" in class "Handler". This seems ok to me.

The code in my Handler is very big, but the method looks something like:

public with sharing class Handler {
  public void sendPatientNotification(Disease__c dis) {
    [some code]
  }
}

Now I get the following error message:

Save error: Method does not exist or incorrect signature: Handler.sendPatientNotification(SOBJECT:Disease__c)

I don't understand what I am doing wrong, because my method does exist and the signature doesn't seem to be incorrect either.


EDIT: When changing my code to call a static method on the Handler, I am still receiving the following error: Syntax Error when attempting to save my Visualforce page.

1 Answer 1

1

You are trying to call sendPatientNotification as if it were a static method. Try changing your Handler class to:

public with sharing class Handler {
  public static void sendPatientNotification(Disease__c dis) {
    [some code]
  }
}

Alternatively, you could change your Controller to create an instance of Handler as well:

public void resendEmails (Disease__c dis) {
    Disease__c d = dis;
    Handler handle = new Handler();
    handle.sendPatientNotification(dis);
}

To answer your EDIT, you now have a problem with your Visualforce page because of the way you are trying to set your action. First off, your Visualforce page references resendEmailsToPatients while your controller method is resendEmails. I assume it is just a typo from cleaning up code to show here, but watch out for that.

Secondly, you are setting the action incorrectly. It does not support passing parameters the way you are trying to do it. Unfortunately, <apex:commandButton> doesn't support passing parameters through it at all. What you want will to do is change your commandButton to something that does support <apex:param>, most likely either a <apex:commandLink> or an <apex:actionSupport>. Assuming you want to keep the button, we can try something like:

<apex:commandButton value="Resend Email" style Class="options">
    <apex:actionSupport event="onclick" action="{!resendEmailsToPatients}">
        <apex:param assignTo="{!selectedDiseaseId}" value="{!Disease__c.Id}"/>
    </apex:actionSupport>
</apex:commandButton>

In this scenario, selectedDiseaseId should be a property on the controller.

NOTE: I haven't run any of this code myself so I can't guarantee it will work correctly the first time you try it. You may need to tweak it a bit.

5
  • Thanks, now this error is gone, but I get an error for the Visualforce Button code. It just says "Syntax error". Do you know how it's supposed to be written? Thanks
    – user8737
    Jun 26, 2014 at 12:04
  • @user8737 I updated your question and my answer with more details. If this helps you, feel free to give an upvote and mark this as your answer. Jun 26, 2014 at 12:24
  • Thank you for your help. Now I get an error: Formula expression is required for attribute assignTo in <apex:param> I wonder if this has to do that the Visualforce page has Disease__c as a Standard Controller and is then extended by my controller class.
    – user8737
    Jun 26, 2014 at 12:53
  • Sorry, I mistyped some of my code. As I mentioned in my post, this wasn't compiled or run myself at all. I just had to add the {!...} notation. Jun 26, 2014 at 12:55
  • Ah, ok - that makes sense now. My error now says that the method is unknown. I assume this is because my visualforce page references Disease__c as standard controller. and then I write extensions and refer to the controller that I put this code in.
    – user8737
    Jun 26, 2014 at 12:58

You must log in to answer this question.

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