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?

  • If you are using apex-mdapi I assume each web service call will be an independent transaction so you will not be able to do a rollback. What API are you using?
    – Keith C
    Commented Sep 9, 2015 at 10:40

1 Answer 1


Could you use the Salesforce database rollback commands?

Savepoint sp = Database.setSavepoint();



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
    Commented 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
    Commented Sep 15, 2015 at 9:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .