Salesforce ~ Microsoft Dynamic CRM Integration Part 2

The post discusses integration between Salesforce and Microsoft Dynamic CRM. It details how to fetch opportunities from MS Dynamic CRM to Salesforce by passing an AccessToken to the getOpportunitiesFromMSDynamic() method. The response, in JSON format, can be parsed to suit the user's needs and applied to Salesforce objects.

part2_1

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 = ' https://yourdomain.api.crmX.dynamics.com/api/data/v9.0/opportunities?$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.setEndpoint(endpointURL);
req.setHeader('Accept','application/json');
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');
req.setMethod('GET');
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.
parser.nextToken();
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:

 

Thanks

Arun Kumar

Arun Kumar
Arun Kumar

Arun Kumar is a Salesforce Certified Platform Developer I with over 7+ years of experience working on the Salesforce platform. He specializes in developing custom applications, integrations, and reports to help customers streamline their business processes. Arun is passionate about helping businesses leverage the power of Salesforce to achieve their goals.

Articles: 162

One comment

Leave a Reply

Discover more from SFDC Lessons

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from SFDC Lessons

Subscribe now to keep reading and get access to the full archive.

Continue reading