void CreateOpportunity(List <Entity.OpportunityEntity> opportunities, LoginResult Session, Opportunity opportunity)
        {
            if (opportunities.Count > 0)
            {
                Logger.Info("Remaining opportunities which are ready to be posted to Salesforce are: " + opportunities.Count.ToString());
                //3. Create Opportunity
                Logger.Info("------------Started posting opportunities------------");
                var responseCreateOpportunities = opportunity.CreateOpportunities(opportunities, Session.sessionId);


                if (String.IsNullOrEmpty(responseCreateOpportunities.salesforceErrorMessage))
                {
                    Logger.Info("------------Finished posting opportunities. Count:" + opportunities.Count.ToString() + "-------------");

                    //List<String> otisIDs = new List<string>();
                    int receivedResponseCount = 0;

                    var    postedOpportunityCount = opportunities.Count;
                    string OrderIDs = String.Empty;
                    var    otisIDs  = opportunities.Select(row => row.OrderID).ToList <int>();

                    if (otisIDs != null)
                    {
                        foreach (var otisID in otisIDs)
                        {
                            OrderIDs = OrderIDs + Convert.ToString(otisID) + ",";
                        }
                        if (!String.IsNullOrEmpty(OrderIDs))
                        {
                            OrderIDs = "(" + OrderIDs.TrimEnd(',') + ")";

                            Logger.Info("------------Started updating posted opportunity Timestamp in DM------------");
                            //Record the Posted DateTime stamp in Order Table
                            opportunity.UpdateOpportunity(OrderIDs, String.Empty, "POSTEDDATETIME", DateTime.Now);
                            Logger.Info("------------Finished updating posted opportunity Timestamp in DM------------");
                        }
                    }
                    //Log mention the number of opportunities records posted are
                    var externalIDs        = opportunities.Select(row => row.ExternalID).ToList <String>();
                    int responseRetryCount = 0;

                    addOpportunitiesResponse responseOpportunities = null;
                    var RetryCount = Convert.ToInt32(ConfigurationManager.AppSettings["RetryCount"]);
                    //Continue the loop until the count posted doesn't meet
                    do
                    {
                        if (responseRetryCount == RetryCount)
                        {
                            Logger.Info("Number of re-tries are exhausted. Process treminated. Retry count: " + RetryCount.ToString());
                            break;
                        }

                        Logger.Info("Wait for 30 secs to receive the opportunity response. Retry Count:" + responseRetryCount.ToString());
                        //Wait for 30 seconds to get the response
                        System.Threading.Thread.Sleep(30000);

                        Logger.Info("------------Started requesting opportunities response------------");
                        //4. Get response from opportunity
                        responseOpportunities = opportunity.GetOpportunitiesAsynchResponse(externalIDs, Session.sessionId);
                        if (responseOpportunities != null)
                        {
                            var responseInserted = responseOpportunities.inserted;
                            var responseRejected = responseOpportunities.rejected;
                            var overCapacity     = responseOpportunities.overCapacity;

                            if (String.IsNullOrEmpty(responseOpportunities.salesforceErrorMessage))
                            {
                                int insertedCount = 0;

                                int RejectedCount = 0;

                                if (responseInserted != null)
                                {
                                    insertedCount = responseInserted.Count();
                                }
                                if (responseRejected != null)
                                {
                                    RejectedCount = responseRejected.Count();
                                }
                                receivedResponseCount = insertedCount + RejectedCount;
                                Logger.Info("Opportunities posted are: " + postedOpportunityCount.ToString() + " and received resoponse are: " + receivedResponseCount.ToString());

                                if (overCapacity != null)
                                {
                                    Logger.Info("Record(s) are still awaiting to be processed in Salesforce. Count: " + overCapacity.Count().ToString());
                                }
                            }
                            else
                            {
                                receivedResponseCount = postedOpportunityCount;
                            }

                            responseRetryCount = responseRetryCount + 1;
                        }
                        //Keep looping through until the number of records posted are not met with response received count
                    } while (postedOpportunityCount != receivedResponseCount);

                    if (receivedResponseCount > 0)
                    //if (postedOpportunityCount == receivedResponseCount)
                    {
                        if (responseOpportunities != null)
                        {
                            if (String.IsNullOrEmpty(responseOpportunities.salesforceErrorMessage))
                            {
                                if (responseOpportunities.inserted != null)
                                {
                                    Logger.Info("Successfull response count received are: " + responseOpportunities.inserted.Count().ToString());

                                    string insertedOtisIDs = String.Empty;

                                    foreach (var inserted in responseOpportunities.inserted)
                                    {
                                        insertedOtisIDs = insertedOtisIDs + inserted.otisId + ",";
                                        var identifiers = inserted.otisId.Split('_');
                                        opportunity.UpdateOpportunity(identifiers[1], inserted.opportunityKey, "REFERENCE", Convert.ToDateTime(identifiers[2]));
                                    }

                                    insertedOtisIDs = insertedOtisIDs.TrimEnd(',');
                                    Logger.Info("Successfull OtisIDS are: " + insertedOtisIDs.ToString());
                                }

                                if (responseOpportunities.rejected != null)
                                {
                                    Logger.Info("Rejected response count received are: " + responseOpportunities.rejected.Count().ToString());

                                    string rejectedOtisIDs = String.Empty;
                                    foreach (var rejected in responseOpportunities.rejected)
                                    {
                                        rejectedOtisIDs = rejectedOtisIDs + rejected.otisId + ",";
                                        var identifiers = rejected.otisId.Split('_');
                                        opportunity.UpdateOpportunity(identifiers[1],
                                                                      "Opportunity failed to create in Salesforce, error received: " + rejected.salesforceErrorMessage, "ERROR", Convert.ToDateTime(identifiers[2]));
                                    }
                                    rejectedOtisIDs = rejectedOtisIDs.TrimEnd(',');
                                    Logger.Info("Rejected OtisIDS are: " + rejectedOtisIDs.ToString());
                                }
                            }
                            else
                            {
                                Logger.Info("No record processed. Salesforce error received in response: " + responseCreateOpportunities.salesforceErrorMessage);
                                Logger.Info("------------Finished requesting opportunities response-------------");
                            }
                            Logger.Info("------------Finished requesting opportunities response-------------");
                        }
                    }
                }
                else
                {
                    Logger.Info("-------------Posting opportunities error received from Salesforce: " + responseCreateOpportunities.salesforceErrorMessage + "------------");
                    Logger.Info("------------Finished successfully posting opportunities-------------");
                }
            }
            else
            {
                Logger.Info("No opportunities are found or left to post to Salesforce.");
            }
        }