1

I need to invoke a REST class exposed in my own developer edition org.   Its a GET Method, and when I test the endpoint using Workbench, I get the expected result.

Now the problem is, I created a new Remote Site Setting and pasted the URL from my own org. In this case remote site setting which i saved is https://ckdomaintest-dev-ed.my.salesforce.com and invoking the same method with same parameters is not executing properly.

I am getting the following error:

System.HttpResponse [Status=Not Found, StatusCode=404]

So I feel the remote site is not being recognized. How do I call my own org?

3
  • That's not what Remote Site Settings do. They allow you to make outbound calls to the given address. They do not affect inbound calls at all.
    – Adrian Larson
    Commented Jul 25, 2017 at 13:56
  • Thanks So much for the quick reply. But how can i invoke method which is exposed in my own org ? any lead be be really helpful. Commented Jul 25, 2017 at 14:05
  • I think you need Salesforce2Salesforce or you can expose the endpoint unauthenticated via Site.
    – Adrian Larson
    Commented Jul 25, 2017 at 14:06

1 Answer 1

2

To do that you need to call the

  1. standard REST API to get you authenticated

  2. Understand the different authentication

  3. Once you are done with authentication call your custom API with access token received from step 2.

You can get sample code from here and here and from the links provided

generally, we don't call rest API in the same org most of the time we call rest api of another salesforce org. if you are already inside of the salesforce org and want to invoke the custom rest api you need to set the header.

req.setHeader('Authorization', 'OAuth '+UserInfo.getSessionId());

Hope this helps.

1
  • If you use 1. instead of 1), you get an ordered list.
    – Adrian Larson
    Commented Jul 25, 2017 at 15:15

You must log in to answer this question.

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