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?