Salesforce ~ Microsoft Dynamic CRM Integration Part 1


“Microsoft Dynamic 365” is ERP and CRM solutions provided by Microsoft. It provides solutions for different apps like Sales, Customer Service, Field Service, Project Service Automation, Finance & Operations, Talent and Retail.

Microsoft “Common Data Service Web API” is a REST API. This Web API provides a RESTful programming experience, we can perform the different operations on organization data with this API.

SignUp 👉 MS Dynamic trail account for development purpose here:


After sign-up login with the credentials | You will see the page shown in the screen below | Select the app.



Now, GoTo Azure portal and follow the steps given below to create an App for integration purpose.

1. Click on Azure Active Directory | App registrations | New registration.


2. Enter the App Name and click on Register.


3. Copy the client ID (This will be used later in the integration code)


4. Click on Certification & secretes | Follow the steps shown in the screenshot. | Copy the client secrete (later we will use this in integration code).


5. Click on API permission and add API Permissions.


6. Click on Manifest and update the settings shown in the screenshot below. | Click on Save.


Yeah! done with all the settings at the Microsoft side. 🙂

The first step for integrating any third party API is Authorization, so let’s authenticate the app (MS Dynamic CRM) and get the AccessToken by making HTTP request/callout using APEX code in Salesforce.

String url = '';
String clientid = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // paste client ID
String clientSec = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX'; //paste client Secrete
String username = 'XXXXXX'; //put your username
String password = 'XXXXXX'; //put your password
String resource = '';
String body = 'client_id='+clientid+'&client_secret='+clientSec+'&username='+username+'&password='+password+'&resource='+resource+'&grant_type=password';
HttpRequest req=new HttpRequest();
req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
Http h=new Http();
HttpResponse res=h.send(req);
system.debug('Response Body: = > '+res.getBody());
// Parse JSON response to get AccessToken.
JSONParser parser = JSON.createParser(res.getBody());
String accessToken = '';
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && 
(parser.getText() == 'access_token')) {
// Get the value.
accessToken += parser.getText();
system.debug('Access Token =: ' + accessToken);

Execute the above code in Salesforce developer console and get the AccessToken.

Response body:

  "token_type": "Bearer",
  "scope": "user_impersonation",
  "expires_in": "3600",
  "ext_expires_in": "3600",
  "expires_on": "1562850806",
  "not_before": "1562846906",
  "resource": "",
  "access_token": "eyJ0eXAiOiJKV1QiLCfdgdfgJhbGciOiJSUzI1NiIsIng1dCI6InU0T2ZORlBId0VCb3NIanRyYXVPYlY4NExuWSIsImtpZCI6InU0T2ZORlBId0VC...."

Now, we got the AccessToken, we can make another request to get data (Opportunity, Account, etc) from Microsoft Dynamic CRM to Salesforce CRM. I will demonstrate this in the 2nd part of this article.

Salesforce ~ Microsoft Dynamic CRM Integration Part 2


Arun Kumar

One comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s