Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (customer.thisOrg.domain_override__c!=null) {
- req.setEndpoint(customer.thisOrg.domain_override__c+'/services/oauth2/token');
- }
- else {
- //check to see if type is sandbox or production/developer
- if(customer.thisOrg.type__c == 'Sandbox'){
- req.setEndpoint('https://test.salesforce.com/services/oauth2/token');
- }
- else{
- req.setEndpoint('https://login.salesforce.com/services/oauth2/token');
- }
- }
- req.setMethod('POST');
- req.setBody('grant_type=password'+
- '&client_id='+' CLIENT_ID'+
- '&client_secret='+'CLIENT_SECRET'+
- '&username='+customer.thisOrg.username__c+
- '&password='+customer.thisOrg.password__c
- );
- httpResponse res = new httpResponse();
- try {
- // send request
- Http http = new Http();
- // capture response
- res = http.send(req);
- system.debug('authentication response: '+ res.getBody());
- }
- catch (exception e) {
- system.debug('error authenticating with customer: '+ e.getMessage());
- customer.log += 'nn error authenticating: ' + e.getMessage();
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement