0

Org 2 has GET Method:

@RestResource(urlMapping='/jobShow/*')
global with sharing class RestJob {

    @HttpGet
    global static List<Job__c> getJob(){
        List<Job__c> jobList;

        try{
            jobList = [SELECT Description__c 
                          FROM Job__c];  
        } catch(Exception e){
            System.debug('Error: ' + e.getMessage());
        }
        return jobList;     
    } 
}

Org 1 has Remote Site with link to Org 2: https://***.lightning.force.com

Org 1 also has a Callout Method:

public class HttpCalloutJob {

    public String getCalloutResponseContents(String url) {
    Http h = new Http();
    HttpRequest req = new HttpRequest();
    req.setEndpoint('https://***.lightning.force.com/services/apexrest/jobShow');  //I don't know: is it right Link or not?
    req.setMethod('GET');

    HttpResponse res = h.send(req);   
    System.debug('Body: ' + res.getBody());
    return res.getBody();     
  }
}

Then I try to Execute this part

Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://***.lightning.force.com/services/apexrest/jobShow');
req.setMethod('GET');
HttpResponse res = h.send(req);      
System.debug('Body: ' + res.getBody());

in Execute Anonymous Window, and become empty Body. But from workbench all is ok: it's not empty.

I think my link is wrong or I didn't connect my Orgs. How can I fix it?

1

Are you passing an access token alongwith with request? You will need a token which will get you access to Org2. When you will make a request to the access token, you will get instance url returned as a part of the response as well.

The instance-url returned is the link/url that you will need to hit.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.