1

I am writing a trigger that uses a callout to update the users subscription on another service. The trigger part is fine. I'm getting an error within the callout class.

There is the callout class, and then there is another one that is basically a Struct (it just has getters and setters for the "Account" of the remote service).

This is basically the struct class,

public class RemoteServiceAccount {
    private Integer id;

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getId(Integer id) {
        return this.id;
    }
}

and then this is the class with the callout method:

public class RemoteServiceSubscription {
    public void change(RemoteServiceAccount remoteServiceAccount) {
        HttpRequest request = new HttpRequest();
        Http http           = new Http();
        String idAsString   = String.valueOf(remoteServiceAccount.getId());

        if (this.accessToken == '') {
            this.auth();
        }

        request.setMethod('POST');
        request.setHeader('Accept', 'application/json');
        request.setHeader('Authorization', 'Bearer ' + this.accessToken);
        request.setEndpoint(this.apiEndPoint + 'customers/' + idAsString);
        request.setBody('expire_date=' + remoteServiceAccount.getExpireDate() + '&subscription=' + remoteServiceAccount.getSubscriptionId());

        try {
            HTTPResponse response = http.send(request);

            if (response.getStatusCode() != 200) {
                System.debug('Remote Service Subscription Update Failed for ID: ' + idAsString);
            }
        } catch (System.CalloutException e) {
            System.debug(e);
        }
    }
}

I am getting the error

Method does not exist or incorrect signature: void getId() from the type RemoteServiceAccount

Which the error technically makes sense, since the method signature is Integer getId(), but I don't understand why it's trying to use void getId()?

** I changed some names, and didn't paste the entire classes, but that is the gist. If I truncated too much info I'd be happy to update.

1 Answer 1

2

Basically getId() is incorrect. Getter always returns the value and Setter will accept value as an argument. So change it as below.

public class RemoteServiceAccount {
    private Integer id;

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return this.id;
    }
}
0

You must log in to answer this question.

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