예제 #1
0
        /// <summary>
        /// Gets data for specified columns of an sobject
        /// </summary>
        public List <sObject> GetDataFromSObject(string sobjectName, List <string> colList, string filter)
        {
            LoginIfRequired();
            colList = RemoveSystemColumns(colList);
            string soql = BuildQuery(sobjectName, colList, filter);

            bool           allResultsReturned = false;
            List <sObject> allResults         = new List <sObject>();
            QueryResult    qr = _binding.query(soql);

            if (qr.size > 0)
            {
                while (!allResultsReturned)
                {
                    allResults.AddRange(qr.records);
                    if (qr.done)
                    {
                        allResultsReturned = true;
                    }
                    else
                    {
                        qr = _binding.queryMore(qr.queryLocator);
                    }
                }
            }

            return(allResults);
        }
예제 #2
0
        private ArrayList SFQueryIds(string SFQuery, out ArrayList messages)
        {
            messages = new ArrayList();
            ArrayList ids = new ArrayList();

            try
            {
                QueryResult qr = null;
                binding.QueryOptionsValue                    = new QueryOptions();
                binding.QueryOptionsValue.batchSize          = 250;
                binding.QueryOptionsValue.batchSizeSpecified = true;

                qr = binding.query(SFQuery);

                bool done      = false;
                int  loopCount = 0;
                while (!done)
                {
                    Console.WriteLine("\nRecords in results set " +
                                      Convert.ToString(loopCount++)
                                      + " - ");
                    // Process the query results
                    if (qr.records == null)
                    {
                        return(ids);                    //return empty
                    }
                    for (int i = 0; i < qr.records.Length; i++)
                    {
                        sObject con = qr.records[i];
                        ids.Add(con.Any[0].InnerText);
                    }

                    if (qr.done)
                    {
                        done = true;
                    }
                    else
                    {
                        qr = binding.queryMore(qr.queryLocator);
                    }
                }
            }
            catch (SoapException e)
            {
                messages.Add("An unexpected error has occurred: " + e.Message +
                             " Stack trace: " + e.StackTrace);
            }
            Console.WriteLine("\nQuery execution completed.");

            return(ids);
        }
예제 #3
0
        internal IEnumerable <sObject> ExecuteQuery(string query)
        {
            var  items = new List <sObject>();
            bool done  = false;

            QueryResult queryResult = _sforceService.query(query);

            if (queryResult.size > 0)
            {
                while (!done)
                {
                    items.AddRange(queryResult.records);

                    if (queryResult.done)
                    {
                        done = true;
                    }
                    else
                    {
                        queryResult = _sforceService.queryMore(queryResult.queryLocator);
                    }
                }
            }
            else
            {
                throw new Exception("No records found. Query: " + query);
            }

            return(items);
        }
예제 #4
0
        /// <summary>
        /// Queries the specified soql query.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="soqlQuery">The soql query.</param>
        /// <returns>List&lt;T&gt;.</returns>
        public List <T> Query <T>(string soqlQuery) where T : sObject
        {
            QueryResult qr   = _binding.query(soqlQuery);
            bool        done = false;

            var l = new List <T>();

            if (qr.size <= 0)
            {
                return(l);
            }
            while (!done)
            {
                if (qr.records != null)
                {
                    l.AddRange(qr.records.Select(r => (T)r));
                }

                if (qr.done)
                {
                    done = true;
                }
                else
                {
                    qr = _binding.queryMore(qr.queryLocator);
                }
            }
            return(l);
        }
예제 #5
0
        private void querySample()
        {
            String soqlQuery = "SELECT FirstName, LastName FROM Contact";

            try
            {
                QueryResult qr   = binding.query(soqlQuery);
                bool        done = false;

                if (qr.size > 0)
                {
                    Console.WriteLine("Logged-in user can see "
                                      + qr.records.Length + " contact records.");

                    while (!done)
                    {
                        Console.WriteLine("");
                        sObject[] records = qr.records;
                        for (int i = 0; i < records.Length; i++)
                        {
                            Contact con   = (Contact)records[i];
                            string  fName = con.FirstName;
                            string  lName = con.LastName;
                            if (fName == null)
                            {
                                Console.WriteLine("Contact " + (i + 1) + ": " + lName);
                            }
                            else
                            {
                                Console.WriteLine("Contact " + (i + 1) + ": " + fName
                                                  + " " + lName);
                            }
                        }

                        if (qr.done)
                        {
                            done = true;
                        }
                        else
                        {
                            qr = binding.queryMore(qr.queryLocator);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No records found.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nFailed to execute query succesfully," +
                                  "error message was: \n{0}", ex.Message);
            }
            Console.WriteLine("\nPress ENTER to continue...");
            Console.ReadLine();
        }
예제 #6
0
        /// <summary>
        /// Gets Salesforce objects.
        /// </summary>
        /// <param name="queryString">Query string.</param>
        /// <returns>List of Salesforce objects.</returns>
        public List <sObject> GetObjects(string queryString)
        {
            var result = new List <sObject>();

            if (CheckConnected())
            {
                QueryResult qr = _binding.queryAll(queryString);

                while (qr.size > 0)
                {
                    result.AddRange(qr.records.ToList()); qr.size = 0;

                    if (!qr.done)
                    {
                        qr = _binding.queryMore(qr.queryLocator);
                    }
                }
            }

            return(result);
        }
        private JArray getCampaignMemberIds(string campaignMemberQuery)
        {
            var allCampaignMemberIds = new JArray();
            var campaignMemberIds    = binding.query(campaignMemberQuery);

            foreach (var campaignMember in campaignMemberIds.records)
            {
                allCampaignMemberIds.Add(campaignMember.Any[0].InnerText);
            }

            while (!campaignMemberIds.done)
            {
                campaignMemberIds = binding.queryMore(campaignMemberIds.queryLocator);
                foreach (var campaignMember in campaignMemberIds.records)
                {
                    allCampaignMemberIds.Add(campaignMember.Any[0].InnerText);
                }
            }

            return(allCampaignMemberIds);
        }