Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //We can also store our username password in custom setting.
- String username='xxx';//salesforce username
- String password='xxxx';//EUe4eHjMxXb8UFco1SPcpsZL9';//salesforce password+securitytoken
- // Generating the Access Token
- HttpRequest req = new HttpRequest();
- req.setMethod('POST');
- req.setEndpoint('https://login.salesforce.com/services/oauth2/token');// this is the OAuth endpoint where this request will be hit
- req.setBody('grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password);
- Http http = new Http();
- HTTPResponse res = http.send(req);
- String str = res.getBody();
- wrapObj = (Wrapper)Json.deserialize(str,Wrapper.class);
- accessToken = wrapObj.access_token;
- instanceUrl = wrapObj.instance_url;
- methodGet();
- }
- // Retrieve the Contacts from the otehr org.
- public void methodGet(){
- HttpRequest req = new HttpRequest();
- req.setMethod('GET');
- //req.setEndpoint(wrapObj.instance_url+'/services/apexrest/Account/getAccountById?name=champaKAli');
- req.setEndpoint('https://lightningwebsite-dev-ed.my.salesforce.com/services/apexrest/AccountService');
- req.setHeader('Authorization', 'Bearer'+wrapObj.access_token);
- Http http = new Http();
- HTTPResponse res = http.send(req);
- System.debug('***Response***** ' + res.getBody());
- //---------------------Here ------------------
- /*JSONParser parser = JSON.createParser(res.getBody());
- do{
- parser.nextToken();
- }while(parser.hasCurrentToken() && !'records'.equals(parser.getCurrentName()));
- parser.nextToken();
- List<account> acc = (List<Account>) parser.readValueAs(List<Account>.class);*/
- }
- public Contact con {get;set;}
- public String s1 {get;set;}
- public String accessToken;
- public String instanceUrl;
- public Wrapper wrapObj{get;set;}
- // Wrapper Class to Store the value from the Jason.
- public class Wrapper{
- String id;
- String instance_url;
- String access_token;
- String issued_at;
- String signature;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement