Salesforce ~ Microsoft Dynamic CRM Integration Part 2


Salesforce ~ Microsoft Dynamic CRM Integration Part 1

Fetch Opportunities from MS Dynamic CRM to Salesforce:

Pass the AccessToken in getOpportunitiesFromMSDynamic() method that we got in Part 1.

public class MSDynamicOpptyGETRequest {

public static void getOpportunitiesFromMSDynamic(String accessToken){
String endpointURL = '$select=name,opportunityid,actualclosedate,budgetamount,closeprobability,createdon,description,discountamount,emailaddress,estimatedclosedate,modifiedon,need,opportunityratingcode,salesstage,statecode,statuscode,totalamount&$expand=customerid_account($select=name)&$top=30';
HttpRequest req=new HttpRequest();
req.setHeader('OData-MaxVersion', '4.0');
req.setHeader('OData-Version', '4.0');
req.setHeader('Authorization', 'Bearer '+accessToken);
req.setHeader('Content-Type','application/json; odata.metadata=minimal');
Http h=new Http();
HttpResponse res=h.send(req);
system.debug('Accounts: ' + res.getBody());
//JSON Parser
JSONParser parser = JSON.createParser(res.getBody());
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && 
(parser.getText() == 'name')) {
// Get the value.
system.debug('Opportunity Name->: '+parser.getText());

You will get the response in JSON format, parse the JSON data according to your need and insert/update them in your Salesforce object.

Important Links:



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 )

Twitter picture

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

Facebook photo

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

Connecting to %s