Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HttpCalloutJob {
- public final String consumerKey = '****';
- public final String consumerSecret = '****';
- public final String username = '****@nihon.com';
- public final String password = 'MySfPassword****';
- public final String reqbody = 'grant_type=password&client_id='+consumerKey+'&client_secret='+consumerSecret+'&username='+username+'&password='+password;
- public void getCalloutResponseContents() {
- Http h = new Http();
- HttpRequest req = new HttpRequest();
- req.setBody(reqbody);
- req.setMethod('GET');
- req.setEndpoint('https://***.lightning.force.com/services/oauth2/token');
- HttpResponse res = h.send(req);
- OAuth2 objAuthenticationInfo = (OAuth2)JSON.deserialize(res.getbody(), OAuth2.class);
- System.debug('Body: ' + res.getBody());
- if(objAuthenticationInfo.access_token!=null){
- Http h1 = new Http();
- HttpRequest req1 = new HttpRequest();
- req1.setHeader('Authorization','Bearer '+objAuthenticationInfo.access_token);
- req1.setHeader('Content-Type','application/json');
- req1.setHeader('accept','application/json');
- req1.setHeader(???); //I don't know, what I need to put inside
- req1.setMethod('GET');
- req1.setEndpoint('https://***.lightning.force.com/services/apexrest/jobShow');
- HttpResponse res1 = h1.send(req1);
- System.debug('RESPONSE_BODY '+res1.getbody());
- }
- }
- public class OAuth2{
- public String id{get;set;}
- public String issued_at{get;set;}
- public String instance_url{get;set;}
- public String signature{get;set;}
- public String access_token{get;set;}
- }
- }
Add Comment
Please, Sign In to add comment