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

One comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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