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?

0

1 Answer 1

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();
}
0

You must log in to answer this question.

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