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

            using (System.RunAs(newUser))
            {
            }
        }
Exemplo 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);
 }
Exemplo 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);
     }
 }
Exemplo 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++)
            {
            }
        }
Exemplo 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");
     }
 }
Exemplo 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());
        }
Exemplo n.º 10
0
 public ClassInitialization()
 {
     contactList = Soql.Query <Contact>("SELECT ID FROM Contact LIMIT 1");
 }
Exemplo 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);
 }
Exemplo n.º 12
0
 public static void forSoql()
 {
     foreach (Contact contactList in Soql.Query <Contact>("SELECT Id, Name FROM Contact"))
     {
     }
 }
Exemplo 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");
 }
Exemplo n.º 14
0
        public static List <Contact> getContacts()
        {
            List <Contact> contacts = Soql.Query <Contact>("SELECT Id, Email, Phone FROM Contact");

            return(contacts);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo n.º 17
0
 public Database.QueryLocator queryLocator(Database.BatchableContext bc)
 {
     return(Database.getQueryLocator(Soql.Query <Contact>("SELECT Id FROM Contact")));
 }