I am importing some metadata via Excel Sheet in salesforce org. THis functionality comes into play when I click import button through my package. I want to create a functionality that whenever I click on Cancel button. All the objects, profiles, roles that are being created in the org, should be deleted. How can I achieve this functionality? Or in simple terms, how can I create rollback functionality in salesforce?
1 Answer
Could you use the Salesforce database rollback commands?
Savepoint sp = Database.setSavepoint(); and
Database.rollback(sp); Reference is here https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_database.htm
- I tried this code. I called the rollback method in the catch block , and initiated the savepoint in the global section of the class. But I am getting an error saying: "You have uncommitted work pending. Please commit or rollback before calling out".happy– happy2015-09-15 06:20:50 +00:00Commented Sep 15, 2015 at 6:20
- This doesn't sound like the error is occurring because of the rollback, it sounds like you are making a webservice callout. You cannot perform a DML operation prior to a callout. All the DML operations should be invoked only after you are done with callouts.Doug B– Doug B2015-09-15 09:45:04 +00:00Commented Sep 15, 2015 at 9:45