3

I have a class with this method, which I borrowed from another answer here on Salesforce Stackexchange:

public String removeHtml(String stringWithHtml) {
    String cleanString = '';
    if (stringWithHtml != null) {
        cleanString = stringWithHtml.replaceAll('<[^>]+>',' ');
    }
    return cleanString; 
}

A little later in the class, I have a method which has this code in it:

String summary = (String)i.get('summary');
summary = removeHtml(summary);

I get this error:

Method does not exist or incorrect signature: removeHtml(String)

But the method does exist, and the signature is correct. Why would I get this error?

7

You'll get this error if you try to call a non-static method in a static method in the same class. Consider the example below:

public class TestClass {

    public TestClass() {}

    public void SomethingInstanced() {}

    public static void Something() {
        SomethingInstanced();
    }

}

You'll get an error:

Method does not exist or incorrect signature: SomethingInstanced()

You need to create an instance of the object with the method, and call the method off of this instance. The snippet below should act as an example of this:

public static void Something() {
    TestController c = new TestController();

    c.SomethingInstanced();
}
| improve this answer | |

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.