What is the output of the following code snippet?l Contact CON = new Contact( LastName = 'JOHNSON', LeadSource = 'Web')23 Savepoint sp = Database.setSavepoint();4 insert CON;5 Database.rollback(sp);67 CON.LeadSource = 'Email'8 insert CON;
A. A runtime error will be thrown on line 5. B. The contact record will be inserted with Leadsource value Web. C. A runtime error will be thrown on line 8. D. The contact record will be inserted with Leadsource value Email.
C. A runtime error will be thrown on line 8.
The ID on an sObject inserted after setting a savepoint is not cleared after a rollback. Create new a sObject to insert after a rollback. Attempting to insert the sObject using the variable created before the rollback fails because the sObject variable has an ID. Updating or upserting the sObject using the same variable also fails because the sObject is not in the database and, thus, cannot be updated.