public void Publish_Package_InstalledAndRunning ()
		{
			var clientId = ConfigHelper.ReadAppSetting ("CguSalesforceConnector.FunctionalTests", "ClientId");
			var clientSecret = ConfigHelper.ReadAppSetting ("CguSalesforceConnector.FunctionalTests", "ClientSecret");
			var username = ConfigHelper.ReadAppSetting ("CguSalesforceConnector.FunctionalTests", "Username");
			var password = ConfigHelper.ReadAppSetting ("CguSalesforceConnector.FunctionalTests", "Password");
			var flow = new UsernamePasswordAuthenticationFlow (clientId, clientSecret, username, password);

            var client = new CguSalesforceConnector.SalesforceClient();
			client.Authenticate (flow);

			var users = client.Query<UserStub> ("SELECT Username, Email FROM USER");

			Assert.That (users.Count > 0);
			Assert.IsFalse (String.IsNullOrEmpty (users [0].Username));
			Assert.IsFalse (String.IsNullOrEmpty (users [0].Email));
			Assert.IsTrue (String.IsNullOrEmpty (users [0].Alias));
		}
예제 #2
0
        static void Main(string[] args)
        {

            // See the SalesforceSetupWalkthrough.doc for information on how to configure your SalesForce account

            // from your setup >> create >> apps >> connected apps settings in SalesForce
            const string sfdcConsumerKey = "3MVG9Y6d_Btp4xp4TTfFOaMzmXtEbo_IFXR3.CXyKsFOnlQnN3zdMKM0DHZFTIf5noog9.cP7xSD7X1MwtA.Z";
            const string sfdcConsumerSecret = "6105525243886775936";

            // your user credentials in salesforce
            const string sfdcUserName = "******";
            const string sfdcPassword = "******";

            // your security token form salesforce.  Name >> My Settings >> Personal >>  Reset My Security Token
            const string sfdcToken = "sI7CFyUKKQ2NEjqhGh4fQFqU";

            var client = new  CguSalesforceConnector.SalesforceClient();
            var authFlow = new UsernamePasswordAuthenticationFlow(sfdcConsumerKey, sfdcConsumerSecret, sfdcUserName, sfdcPassword + sfdcToken);
            
            // all actions should be in a try-catch - i'll just do the authentication one for an example
            try
            {
                client.Authenticate(authFlow);
            }
            catch (CguSalesforceConnector.SalesforceException ex)
            {
                Console.WriteLine("Authentication failed: {0} : {1}", ex.Error, ex.Message);
            }

            // create a record using a class instance
            SFCaseUpdate myCase = new SFCaseUpdate();
            myCase.Subject = "This is the subject of my salesforce case";
            myCase.Description = "This is the description of my salesforce case";
            myCase.Rank__c = 5;
           // client.Create("Case", myCase);

            // create a record using an anonymous class and returns the ID
           // string resultID = client.Create("Case", new { Subject = "This is the subject of another salesforce case", Description = "This is the description of that other salesforce case", Rank__c = 5 });

            // query records
            var records = client.Query<SFCase>("SELECT id FROM Account");
            foreach (var r in records)
            {
                Console.WriteLine("Query Records {0}:", r.id);
            }

            // find the record we just added by the ID we captured above in resultID
           // var record = client.FindById<SFCase>("Case", resultID);
            //Console.WriteLine("\n\nRead this record {0} {1} {2} {3} {4}\n\n", record.id, record.CaseNumber, record.Subject, record.Description, record.Rank__c);

            // update that record and set the custom field rank to 1 using an anonymous class.
           // client.Update("Case", resultID, new { Rank__c = 1 });

            // update that record and set the custom field rank to 9001 using a class instance, note that i have to fill in every property from the record or it will push back nulls 
            SFCaseUpdate myupdate = new SFCaseUpdate();
            myupdate.Rank__c = 9001;
           // myupdate.Description = record.Description;
            //myupdate.Subject = record.Subject;
           // client.Update("Case", resultID, myupdate);

            // re-read it to see if it updated correctly, rank should = 9001
            //var record2 = client.FindById<SFCase>("Case", resultID);
            //Console.WriteLine("Read this record again {0} {1} {2} {3} {4}\n\n", record2.id, record2.CaseNumber, record2.Subject, record2.Description, record2.Rank__c);

            // now delete the record I added
           // client.Delete("Case", resultID);


            Console.WriteLine("Hit Enter to Exit");
            Console.ReadKey();
        }