You need to sign in to do that
Don't have an account?
LBS
Integrating with SFDC Apex+oAuth services
Hi There,
With referred to following blog I'm trying to integrate 2 salesforce Orgs. It follows the token requests with the token url. I have created connected Apps on the target env and remote access settings on the source org as suggested.
https://developer.salesforce.com/forums?id=906F00000009ARWIA2
I have created a VF page with a button and in the controller itself i have defined usernames, passwords, clientId/secrets to start the process. I.m getting no errors but it doesn't return the Access URL. Alaways have Null in the debug log. What could possibly go wrong? Something related to connected App settings?
Thanks,
Mudi
With referred to following blog I'm trying to integrate 2 salesforce Orgs. It follows the token requests with the token url. I have created connected Apps on the target env and remote access settings on the source org as suggested.
https://developer.salesforce.com/forums?id=906F00000009ARWIA2
I have created a VF page with a button and in the controller itself i have defined usernames, passwords, clientId/secrets to start the process. I.m getting no errors but it doesn't return the Access URL. Alaways have Null in the debug log. What could possibly go wrong? Something related to connected App settings?
Thanks,
Mudi
All Answers
Find the below blog , it clearly explained salesforce to salesforce integartion .
http://amulhai.blogspot.in/2015/11/salesforce-to-salesforce-integration.html
Here is my code,
VF Page
<apex:page controller="HandleOAuthController">
<apex:form >
<apex:pageBlock title="Retrive Access Token And Process">
<apex:pageBlockSection columns="1">
<apex:commandLink action="{!doAuthorization}" value="Authorize" id="lnCommandLink"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller
public with sharing class HandleOAuthController {
private String username = '';
private String password = '';
private String clientId = '';
private String clientSecret = '';
public class deserializeResponse{
public String id;
public String accessToken;
}
public HandleOAuthController(){
this.username = 'xxx@yahoo.com';
this.password = 'xxxuGwbdHBhYY5EzaCex7K4pzf5';
this.clientId = 'xxVG9YDQS5WtC11qKJsfXwErtfFqFioTmBglcoXTG21dL8TNWoEcgo6ZLGM_jFFib7caOwHoC4ME9kwRYQuCm';
this.clientSecret = 'xx04062233353435285';
}
public String returnAccessToken(HandleOAuthController obj){
String reqBody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setBody(reqBody);
req.SetMethod('POST');
req.setEndpoint('https://login.salesforce.com/services/oauth2/token');
HttpResponse res = h.send(req);
deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);
//HERE THE ACESS TOKEN COMES AS NULL
system.debug('::accessToken::'+resp1.accessToken);
system.debug('::resp1::'+resp1);
return resp1.accessToken;
}
public static void doAuthorization(){
HandleOAuthController ctrl = new HandleOAuthController();
String accessToken;
accessToken = ctrl.returnAccessToken(ctrl);
}
}