What am I doing wrong here? I have an ApexClass named SearchController, which starts with:

public class SearchController 

and which includes these two methods:

public void save_search_results(String sanico_data) {

    // Parse JSON response to get all the totalPrice field values.
    JSONParser parser = JSON.createParser(sanico_data);

    while (parser.nextToken() != null) {
        // Start at the array of invoices.
        if (parser.getCurrentToken() == JSONToken.START_ARRAY) {
        while (parser.nextToken() != null) {
            // Advance to the start object marker to
            //  find next invoice statement object.
            if (parser.getCurrentToken() == JSONToken.START_OBJECT) {
            JSONToken token = parser.getCurrentToken(); 

            // Skip the child start array and start object markers.

public static void fetch(Search__c current_search) { 
    Http httpProtocol = new Http();
    // Create HTTP request to send.
    HttpRequest request = new HttpRequest();
    // Set the endpoint URL.
    String endpoint = 'https://sanico.com/v0/search/' + current_search.Name;
    request.setHeader('Accept', 'application/json');            

    // Send the HTTP request and get the response.
    // The response is in JSON format.
    HttpResponse response = httpProtocol.send(request);

I get this error:

Method does not exist or incorrect signature: save_search_results(string)

But I the method does exist and the signature is correct.

Calling HttpResponse.getBody() returns a String, which is what I give to the method, which is expecting a String.

So what did I do wrong?


You are getting this error because your save_search_results method is not static, but your fetch method is. So the latter cannot see the former. Mark save_search_results as a static method as well.

| 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.