Ejemplo 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");
            }
        }
Ejemplo n.º 2
0
        public static void insertContact(ContactDTO contactToSave)
        {
            Contact contact = new Contact();

            contact.LastName = contactToSave.LastName;
            Soql.insert(contact);
        }
Ejemplo n.º 3
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");
            }
        }
Ejemplo n.º 4
0
        public static void Setup()
        {
            Contact contactNew = new Contact();

            contactNew.LastName = "Jay";
            contactNew.Email    = "*****@*****.**";
            Soql.insert(contactNew);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public PageReference save()
        {
            try
            {
                Soql.insert(contact);
            }
            catch (DmlException e)
            {
                ApexPages.addMessages(e);
            }

            return(null);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        static void testGetIdValue()
        {
            Account a = new Account {
                Name = "Acme"
            };

            Soql.insert(a);
            JSONParse parser = new JSONParse("\"" + a.Id.ToString() + "\"");

            System.assertEquals(a.Id, parser.getIdValue());
            try
            {
                parser = new JSONParse("[1,2,3]");
                parser.getIdValue();
                System.assert(false, "Node is not a valid Id, should have seen an exception about that.");
            }
            catch (JSONParse.InvalidConversionException e)
            {
                System.assertEquals("This value cannot be converted to an Id: [ 1, 2, 3 ]", e.getMessage());
            }
        }