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
[…] Account, etc) from Microsoft Dynamic CRM to Salesforce CRM. I will demonstrate this in the 2nd part of this […]
LikeLike