Salesforce ~ Microsoft Dynamic CRM Integration Part 2

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 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.

This Post Has One Comment

Leave a Reply