Esempio n. 1
0
        /**
         * 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");
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        static void RunAsExample()
        {
            User newUser = Soql.Query <User>("SELECT Id FROM User LIMIT 1");

            using (System.RunAs(newUser))
            {
            }
        }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 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);
     }
 }
Esempio n. 7
0
        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++)
            {
            }
        }
Esempio n. 8
0
 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");
     }
 }
Esempio n. 9
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());
        }
Esempio n. 10
0
 public ClassInitialization()
 {
     contactList = Soql.Query <Contact>("SELECT ID FROM Contact LIMIT 1");
 }
Esempio n. 11
0
 public void TestSoqlApiExample()
 {
     Soql.Query("select id from Customer where email = :email", "*****@*****.**");
     Soql.Query("select id from Customer where email = :email and name = :name", "*****@*****.**", "jay");
     Soql.Query("select id from Customer where email = :email and name = :name and age > :age", "*****@*****.**", "jay", 20);
 }
Esempio n. 12
0
 public static void forSoql()
 {
     foreach (Contact contactList in Soql.Query <Contact>("SELECT Id, Name FROM Contact"))
     {
     }
 }
Esempio n. 13
0
 public static void oneVsListDemo()
 {
     List <Contact> contacts = Soql.Query <Contact>("SELECT Id, Email FROM Contact LIMIT 5");
     List <Contact> contact  = Soql.Query <Contact>("SELECT Id, Email FROM Contact LIMIT 1");
 }
Esempio n. 14
0
        public static List <Contact> getContacts()
        {
            List <Contact> contacts = Soql.Query <Contact>("SELECT Id, Email, Phone FROM Contact");

            return(contacts);
        }
Esempio n. 15
0
        public static List <Contact> getContactByEMail(string email)
        {
            List <Contact> contacts = Soql.Query <Contact>("SELECT Id, Email, Phone FROM Contact WHERE Email = :email", email);

            return(contacts);
        }
Esempio n. 16
0
        public static void ParentChildDemo()
        {
            List <BankAccount__c> bankAccounts = Soql.Query <BankAccount__c>("SELECT Name, Customer__r.Name FROM BankAccount__C LIMIT 1");

            Console.WriteLine(bankAccounts[0].Customer__r.Name);
        }
Esempio n. 17
0
 public Database.QueryLocator queryLocator(Database.BatchableContext bc)
 {
     return(Database.getQueryLocator(Soql.Query <Contact>("SELECT Id FROM Contact")));
 }