public void AnyAction_NotAuthentacated_Exception() { var target = new SalesforceClient(); ExceptionAssert.IsThrowing(new InvalidOperationException("Please, execute Authenticate method before call any REST API operation."), () => { target.Create("TESTE", "TESTE"); }); ExceptionAssert.IsThrowing(new InvalidOperationException("Please, execute Authenticate method before call any REST API operation."), () => { target.Delete("TESTE", "TESTE"); }); ExceptionAssert.IsThrowing(new InvalidOperationException("Please, execute Authenticate method before call any REST API operation."), () => { target.FindById <Exception>("TESTE", "TESTE"); }); ExceptionAssert.IsThrowing(new InvalidOperationException("Please, execute Authenticate method before call any REST API operation."), () => { target.Query <Exception>("TESTE"); }); ExceptionAssert.IsThrowing(new InvalidOperationException("Please, execute Authenticate method before call any REST API operation."), () => { target.Update("TESTE", "TESTE", "TESTE"); }); }
public void FindById_NullOrEmptyId_Exception() { var target = new SalesforceClient(); ExceptionAssert.IsThrowing(new ArgumentException("Argument 'recordId' can't be empty.", "recordId"), () => { target.FindById <Exception>("TESTE", ""); }); }
public void FindById_NullOrEmptyObjectName_Exception() { var target = new SalesforceClient(); ExceptionAssert.IsThrowing(new ArgumentException("Argument 'objectName' can't be empty.", "objectName"), () => { target.FindById <Exception>("", "TESTE"); }); }
static private InspectionJSONClass findInspectionbyOrderNumber(String orderNumber, SalesforceClient client) { var record = client.Query <QueryforIDclass>("SELECT Id From Inspection__c WHERE Name='" + orderNumber + "'"); if (record.Count != 1) { return(null); } else { return(client.FindById <InspectionJSONClass>("Inspection__c", record[0].Id)); } }
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 = "3MVG9JZ_r.QzrS7gHCcJexYMP2UL45ZgzaagHsVXfYSjWwlhU7n2uaxzfsuBNvwjofV70lM9QtA_xYLTxXjgf"; const string sfdcConsumerSecret = "2968907211720668629"; // 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 = "w7UGcyJnOaWX8U7XRCEbIfLYw"; var client = new 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 (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, CaseNumber, Subject, Description, Rank__c FROM Case"); foreach (var r in records) { Console.WriteLine("Query Records {0}: {1} {2}", r.id, r.CaseNumber, r.Subject); } // 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(); }
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 = "3MVG9JZ_r.QzrS7gHCcJexYMP2UL45ZgzaagHsVXfYSjWwlhU7n2uaxzfsuBNvwjofV70lM9QtA_xYLTxXjgf"; const string sfdcConsumerSecret = "2968907211720668629"; // 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 = "w7UGcyJnOaWX8U7XRCEbIfLYw"; var client = new 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 (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, CaseNumber, Subject, Description, Rank__c FROM Case"); foreach (var r in records) { Console.WriteLine("Query Records {0}: {1} {2}", r.id, r.CaseNumber, r.Subject); } // 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(); }