public void TestPolymorphicQueryApi() { // multiple results List <Customer> list = Soql.Query <Customer>("select * from Customer where email = :email and name = :name and age > :age", "*****@*****.**", "jay", 20); Assert.NotNull(list); Assert.AreEqual(3, list.Count); // single result Customer customer = Soql.Query <Customer>("select * from Customer where email = :email and name = :name and age > :age", "*****@*****.**", "jay", 20); Assert.NotNull(customer); Assert.AreEqual("Jay", customer.Name); Assert.AreEqual("*****@*****.**", customer.Email); // query text string query = Soql.Query <Customer>("select * from Customer where email = :email and name = :name and age > :age", "*****@*****.**", "jay", 20); Assert.NotNull(query); Assert.AreEqual("select * from Customer where email = :email and name = :name and age > :age", query); // Database.getQueryLocator(query) var result = Database.GetQueryLocator(Soql.Query <Customer>("select * from Customer where email = :email and name = :name and age > :age", "*****@*****.**", "jay", 20)); Assert.NotNull(result); Assert.AreEqual("select * from Customer where email = :email and name = :name and age > :age", result); }
public static void insertContact(ContactDTO contactToSave) { Contact contact = new Contact(); contact.LastName = contactToSave.LastName; Soql.insert(contact); }
public static void UpdatePhoneTestNotValidEmail() { Demo.UpdatePhone("*****@*****.**", "555-1212"); List <Contact> contacts = Soql.query <Contact>("SELECT ID, Email, Phone FROM Contact WHERE Email = '*****@*****.**'"); System.AssertEquals(contacts.Size(), 0); }
/** * A simple CRUD Example */ public static void CrudExample() { Contact contactNew = new Contact { LastName = "Jay", EMail = "*****@*****.**" }; Soql.insert(contactNew); System.debug(contactNew.Id); List <Contact> contacts = Soql.query <Contact>("SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id", contactNew.Id); foreach (Contact c in contacts) { System.debug(c.Email); c.Email = "*****@*****.**"; } Soql.update(contacts); contacts = Soql.query <Contact>("SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id", contactNew.Id); foreach (Contact c in contacts) { System.debug(c.Email); } Soql.delete(contacts); contacts = Soql.query <Contact>("SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id", contactNew.Id); if (contacts.isEmpty()) { System.debug("Delete Worked"); } }
/** * A simple CRUD Example */ public static void CrudExample() { // Contact contactNew = new Contact(LastName = 'Jay', Email = '*****@*****.**'); Contact contactNew = new Contact(); Soql.insert(contactNew); System.Debug(contactNew.Id); List <Contact> contacts = Soql.query <Contact>(@"SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id", contactNew.Id); foreach (Contact c in contacts) { System.Debug(c.Email); c.Email = "*****@*****.**"; } Soql.update(contacts); contacts = Soql.query <Contact>(@"SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id", contactNew.Id); foreach (Contact c in contacts) { System.Debug(c.Email); } Soql.delete(contacts); contacts = Soql.query <Contact>(@"SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id", contactNew.Id); if (contacts.IsEmpty()) { System.Debug("Delete Worked"); } }
public static List <Contact> getContacts() { List <Contact> contacts = Soql.query <Contact>(@"SELECT Id, Email, Phone FROM Contact"); NoApex.Serilog.LogInfo(contacts.size().ToString()); return(contacts); }
public static void updatePhoneTestValidEmail() { Demo.updatePhone("*****@*****.**", "555-1212"); List <Contact> contacts = Soql.query <Contact>("SELECT ID, Email, Phone FROM Contact WHERE Email = '*****@*****.**'"); System.assertEquals(contacts[0].Phone, "555-1212"); }
public static void UpsertTest() { Contact contactNew = new Contact(); contactNew.LastName = "apexSharp"; contactNew.Email = "*****@*****.**"; Soql.upsert(contactNew); System.debug(contactNew.Id); List <Contact> contacts = Soql.query <Contact>("SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id", contactNew.Id); foreach (Contact c in contacts) { System.debug(c.Email); c.Email = "*****@*****.**"; } Soql.upsert(contacts); contacts = Soql.query <Contact>("SELECT Id, Email FROM Contact WHERE Id = :contactNew.Id", contactNew.Id); foreach (Contact c in contacts) { System.debug(c.Email); } }
public static void ForSoql() { // for soql foreach (Contact contactList in Soql.query <Contact>(@"SELECT Id, Name FROM Contact")) { // do nothing } }
public void InvalidSubctratingExpression() { // Act and Assert Assert.Throws <IlegalExpressionException>(() => Soql .From <TestClass>() .Select((x) => x.MyIntProperty) .Where((x) => x.MyIntProperty - 1 == 12)); }
static void RunAsExample() { User newUser = Soql.query <User>("SELECT Id FROM User LIMIT 1"); using (System.runAs(newUser)) { } }
public static void ForSoql() { foreach (Contact contact in Soql.query <Contact>(@"SELECT Id, Name FROM Contact")) { contact.Name = contact.Name + " (upserted)"; Soql.upsert(contact); } }
public static void InClauseTest() { Contact[] contactList = Soql.query <Contact>(@"SELECT Id, Email, Phone FROM Contact WHERE Email IN ('*****@*****.**', '*****@*****.**')"); string[] emails = new string[] { "*****@*****.**", "*****@*****.**" }; Contact[] contactListThree = Soql.query <Contact>(@"SELECT Id, Email, Phone FROM Contact WHERE Email IN :emails", emails); Contact[] contactListOne = Soql.query <Contact>(@"SELECT Id, Email FROM Contact LIMIT 2"); Contact[] contactListTwo = Soql.query <Contact>(@"SELECT Id FROM Contact WHERE Id IN :contactListOne", contactListOne); }
public static void Setup() { Contact contactNew = new Contact(); contactNew.LastName = "Jay"; contactNew.Email = "*****@*****.**"; Soql.insert(contactNew); }
public void mapSoqlExample() { // Map<Id, Contact> m = new Map<Id, Contact>(Soql.Query<Contact>("SELECT Id FROM Jay__c")); Map<ID, Contact> m = new Map<ID, Contact>(Soql.Query<Contact>("SELECT Id, Name FROM Contact LIMIT 10")); foreach (ID idKey in m.keySet()) { Contact contact = m.get(idKey); } }
public static void MethodOne() { foreach (Account a in Soql.query <Account>(@"SELECT Id FROM Account")) { System.Debug(a.Id); } for (int i = 0; i < 10; i++) { } }
public static void getContactsTest() { Contact contact = new Contact(); contact.Email = randomWithLimit() + "@jay.com"; contact.Phone = "111-111=1111"; contact.LastName = "jay"; Soql.insert(contact); List <Contact> contacts = Demo.getContacts(); System.assert(contacts.size() > 0); }
public static void PostTest() { RestContext.Request = new RestRequest(); RestContext.Response = new RestResponse(); ClassRest.ContactDTO contact = new ClassRest.ContactDTO(); contact.LastName = "LastName"; RestContext.Request.RequestBody = Blob.valueOf(JSON.serialize(contact)); ClassRest.post(); System.assertEquals(200, RestContext.Response.StatusCode); List <Contact> contacts = Soql.query <Contact>("SELECT Id FROM Contact WHERE LastName = 'LastName'"); System.assertEquals(1, contacts.size()); }
public static void VariableScope(int x) { if (x == 5) { List <Contact> objectList; objectList = Soql.query <Contact>(@"SELECT Id FROM Contact LIMIT 5"); } else { List <Contact> objectList; objectList = Soql.query <Contact>(@"SELECT Id FROM Contact LIMIT 5"); } }
public PageReference save() { try { Soql.insert(contact); } catch (DmlException e) { ApexPages.addMessages(e); } return(null); }
public static void updatePhoneTestNotValidEmail() { Contact contact = new Contact(); contact.Email = randomWithLimit() + "@jay.com"; contact.Phone = "111-111=1111"; contact.LastName = "jay"; Soql.insert(contact); Demo.updatePhone(contact.Email, "555-1212"); List <Contact> contacts = Soql.query <Contact>("SELECT ID, Email, Phone FROM Contact WHERE Email = '@jay.com'"); System.assertEquals(contacts.size(), 0); }
public void NoSelectTest() { // Arrange var expected = SetUpExpectedSelect("MyIntProperty, MyStringProperty, MyBoolProperty__c, MyDateTimeProperty__c, MyDateTimeOffsetProperty, MyEnumProperty"); // Act var actual = Soql .From <TestClass>() .Build(); // Assert Assert.Equal(expected, actual); }
public void SingleNestedMember() { // Arrange var expected = SetUpExpectedSelect("MyChild__r.MyBoolProperty__c"); // Act var actual = Soql .From <TestClass>() .Select((x) => x.MyChild.MyBoolProperty) .Build(); // Assert Assert.Equal(expected, actual); }
public void MultipleMemberWithNested() { // Arrange var expected = SetUpExpectedSelect("MyDateTimeProperty__c, MyChild__r.MyBoolProperty__c"); // Act var actual = Soql .From <TestClass>() .Select((x) => new { x.MyDateTimeProperty, x.MyChild.MyBoolProperty }) .Build(); // Assert Assert.Equal(expected, actual); }
public void AndCondition() { // Arrange var expected = SetUpExpectedWhere(@"(MyChild__r.MyIntProperty = 22 AND MyStringProperty != null)"); // Act var actual = Soql .From <TestClass>() .Select((x) => x.MyIntProperty) .Where((x) => x.MyChild.MyIntProperty == 22 && x.MyStringProperty != null) .Build(); // Assert Assert.Equal(expected, actual); }
public void EnumWithoutAttributeComparision() { // Arrange var expected = SetUpExpectedWhere(@"MyEnumProperty = 'CaseC'"); // Act var actual = Soql .From <TestClass>() .Select((x) => x.MyIntProperty) .Where((x) => x.MyEnumProperty == TestEnum.CaseC) .Build(); // Assert Assert.Equal(expected, actual); }
public void MultipleCondition() { // Arrange var expected = SetUpExpectedWhere(@"(MyChild__r.MyIntProperty = 22 OR (MyChild__r.MyChild__r.MyEnumProperty = 'CaseC' AND MyEnumProperty = 'Case A'))"); // Act var actual = Soql .From <TestClass>() .Select((x) => x.MyIntProperty) .Where((x) => x.MyChild.MyIntProperty == 22 || (x.MyChild.MyChild.MyEnumProperty == TestEnum.CaseC && x.MyEnumProperty == TestEnum.CaseA)) .Build(); // Assert Assert.Equal(expected, actual); }
public void SimpleIntegerComparision() { // Arrange var expected = SetUpExpectedWhere("MyIntProperty = 12"); // Act var actual = Soql .From <TestClass>() .Select((x) => x.MyIntProperty) .Where((x) => x.MyIntProperty == 12) .Build(); // Assert Assert.Equal(expected, actual); }
public void SimpleDateComparision() { // Arrange var expected = SetUpExpectedWhere("MyDateTimeProperty__c = 2020-02-12T12-14-41Z"); // Act var actual = Soql .From <TestClass>() .Select((x) => x.MyIntProperty) .Where((x) => x.MyDateTimeProperty == new DateTime(2020, 02, 12, 12, 14, 41)) .Build(); // Assert Assert.Equal(expected, actual); }
public void IncludeWithSelectTest() { // Arrange var expected = SetUpExpectedSelect("MyBoolProperty__c, MyChild__r.MyChild__r.MyIntProperty, MyChild__r.MyChild__r.MyStringProperty, MyChild__r.MyChild__r.MyBoolProperty__c, MyChild__r.MyChild__r.MyDateTimeProperty__c, MyChild__r.MyChild__r.MyDateTimeOffsetProperty, MyChild__r.MyChild__r.MyEnumProperty"); // Act var actual = Soql .From <TestClass>() .Select(x => x.MyBoolProperty) .Include(x => x.MyChild.MyChild) .Build(); // Assert Assert.Equal(expected, actual); }
public void FindByFieldValue(string fieldName, string fieldValue, Soql.ComparisonOperator comparisonOperator, bool expected) { var result = this.ContactsApi.FindByFieldValue(fieldName, fieldValue, comparisonOperator, 0, int.MaxValue); Assert.NotNull(result); Assert.AreEqual(expected, result.Any()); }
public int GetTotalCountByFieldValue(string fieldName, string fieldValue, Soql.ComparisonOperator comparisonOperator) { return this.ContactsApi.GetTotalCountByFieldValue(fieldName, fieldValue, comparisonOperator); }