@api properties are set before connectedCallback is called.
The connectedCallback() hook is invoked with the initial properties passed to the component. If a component derives its internal state from the properties, it's better to write the logic in a setter than in connectedCallback(). For sample code, see this StackExchange post by Salesforce engineer, Pierre-Marie Dartus.
That means that, for an initial callback, you can use connectedCallback():
connectedCallback() {
this.callApex(); // properties are already set
}
If the property changes, then you do may need to react to it via a setter:
@api set recordId(value) {
this._recordId = value;
this.callApex();
}
// Set @api only once on get or set, not both
get recordId() {
return this._recordId;
}
If that's the case, then connectedCallback isn't necessary, as you'll get the callback called every time the property changes. That's probably ideal, since the parent is allowed to change the value at any time.
Finally, you can always wire the method if you want the callback handled automatically:
@wire(myApexMethod, { recordId: '$recordId' })
apiData;
Or:
@wire(myApexMethod, { recordId: '$recordId' })
apiDataHandler({data, error}) {
if(data) {
// Do something with the data
}
if(error) {
// Display an error
}
}