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() { foreach (Contact contact in Soql.query <Contact>(@"SELECT Id, Name FROM Contact")) { contact.Name = contact.Name + " (upserted)"; Soql.upsert(contact); } }