You need to sign in to do that
Don't have an account?
Simon234
Apex Callout from one Org to another with method GET
Org 2 has GET Method:
Org 1 also has a Callout Method:
I think my link is wrong or I didn't connect my Orgs. How can I fix it?
@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?
Directly we cannot connect to other org.To connect first we need to authentication with Oauth.
Steps to get Accestoken :
Create one connected app it will contain client id ,client secret and callback URL.
Ex :
http://salesforceprasad.blogspot.com/2017/04/how-to-test-salesforce-rest-api.html
Once u receive access token then you need the pass that token in your class
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For SFDC Support: varaprasad4sfdc@gmail.com
Salesforce latest interview questions :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
Note : if we excute above code in anonymous window it will show null on responce.
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For SFDC Support: varaprasad4sfdc@gmail.com
Salesforce latest interview questions :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
try below code
iit will work
No offense but I'm little unclear about it.
Because it's still two different ORGs, how you gonna prove the authorization to the other ORG?
Like the Session-Id is generated with credentials of another ORG and being passed to another. How the ORG decides whether you've got bucks in your pocket and should be allowed or it shouldn't be.
Or if it is allowed, can't we access any other org with SF login or test URL?