I tested this code in Execute Anonymous and it worked, but when I hooked it up with my component, I found out this error: INVALID_SESSION_ID: This session is not valid for use with the REST API.
I asked about this question and I was pointed to this document, which gave me the solution: use Named Credentials!
I remember seeing this Named Credentials and how cool they were, but I had not set them up before to make a call back to my ORG to perform API operations, and as I ended up learning it’s quite a complex process. I had to create three independent things to get this done:
- A Connected App
- An Auth. Provider
- A Named Credential
And setting them up was not a trivial process!
These are the steps you should follow if you want to get this working: