I am trying to update a Salesforce record but I have to update it using an older version of Salesforce API (v44) due to some new standard behavior changes salesforce made. I am doing this by making a REST callout to my salesforce org from Apex and I am successfully able to test it using workbench Rest Explorer. When I make this call using Apex or Execute anonymous, I get this error:
"[{"message":"Access from current IP address is not allowed","errorCode":"INSUFFICIENT_ACCESS"}]"
The environment I am working in is very locked down and does have an IP Range restriction, but I am already in the network while making this callout and as I said earlier I was able to make the callout using Workbench.
Where can I look to fix this error?
The code for the callout:
String SF_URL = URL.getSalesforceBaseUrl().toExternalForm();
String restAPIURL = SF_URL + '/services/data/v44.0/sobjects/Account/' + accId + '?_HttpMethod=PATCH';
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(restAPIURL);
request.setHeader('X-HTTP-Method-Override','PATCH');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
// Set the body as a JSON object
request.setBody('{"OwnerId":"' + AccOwner + '"}');
HttpResponse response = http.send(request);