public static SforceServiceWrapper StartSession(string username, string password, string securityToken)
 {
     SforceServiceWrapper service = new SforceServiceWrapper();
     LoginResult lr = service.login(username, password + securityToken);
     service.Url = lr.serverUrl;
     return service;
 }
 public static SforceServiceWrapper GetSession(string sessionId)
 {
     SforceServiceWrapper service = new SforceServiceWrapper();
     service.SessionHeaderValue = new SessionHeader();
     service.SessionHeaderValue.sessionId = sessionId;
     return service;
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //Create Salesforce binging with username and password
            //sforceService = SalesforceSession.StartSession("user name", "password", "security token");
            sforceService = SalesforceSession.StartSession("*****@*****.**", "scmy_209_XX_!", "KwgCnbIa0QRHEEpPvXV6DaZb");

            List<sObject> accounts = AccountProvider.retrieve10Accounts(sforceService);
            foreach (sObject account in accounts)
                Console.WriteLine(string.Format("{0} {1}", account.Id, account.Any[1].InnerText));

            Console.WriteLine("");
            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();
        }
Ejemplo n.º 4
0
        public static void DeletesObjects(SforceServiceWrapper sforceService, List<sObject> sObjects)
        {
            if (sObjects.Count == 0) return;

            List<string> deleteBatch = new List<string>();
            foreach (sObject sobject in sObjects)
            {
                deleteBatch.Add(sobject.Id);
                //insert 200 records at a time
                if (deleteBatch.Count == MODIFY_BATCH_SIZE)
                {
                    DeleteResult[] results = sforceService.delete(deleteBatch.ToArray());
                    Helper.CheckResultErrors(results);

                    deleteBatch.Clear();
                }
            }
            //insert remaining records
            if (deleteBatch.Count > 0)
            {
                DeleteResult[] results = sforceService.delete(deleteBatch.ToArray());
                CheckResultErrors(results);
            }
        }
Ejemplo n.º 5
0
 public static List<sObject> retrieve10Accounts(SforceServiceWrapper sforceService)
 {
     return Helper.QuerysObjects(sforceService, "SELECT Id, Name FROM Account LIMIT 10");
 }
Ejemplo n.º 6
0
        public static List<sObject> QuerysObjects(SforceServiceWrapper sforceService, string soql)
        {
            sforceService.QueryOptionsValue = new sforce.QueryOptions();
            sforceService.Timeout = SOAP_TIMEOUT;
            sforceService.QueryOptionsValue.batchSize = RETRIEVE_BATCH_SIZE;
            sforceService.QueryOptionsValue.batchSizeSpecified = true;

            List<sObject> result = new List<sObject>();
            QueryResult qr = sforceService.query(soql);

            bool queryMore = true;
            while (queryMore && (qr.size > 0))
            {
                foreach (sObject sobject in qr.records)
                    result.Add(sobject);

                if (qr.done)
                    queryMore = false;
                else
                    qr = sforceService.queryMore(qr.queryLocator);
            }
            return result;
        }
Ejemplo n.º 7
0
        public static void InsertsObjects(SforceServiceWrapper sforceService, List<sObject> sObjects)
        {
            if (sObjects.Count == 0) return;

            List<sObject> insertBatch = new List<sObject>();
            foreach (sObject sobject in sObjects)
            {
                insertBatch.Add(sobject);
                //insert 200 records at a time
                if (insertBatch.Count == MODIFY_BATCH_SIZE)
                {
                    SaveResult[] results = sforceService.create(insertBatch.ToArray());
                    Helper.CheckResultErrors(results);

                    insertBatch.Clear();
                }
            }
            //insert remaining records
            if (insertBatch.Count > 0)
            {
                SaveResult[] results = sforceService.create(insertBatch.ToArray());
                CheckResultErrors(results);
            }
        }