0

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
  • 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? Commented Sep 9, 2015 at 10:40

1 Answer 1

2

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

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.