function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
apurswaniapurswani 

Do we have savepoints and rollback in .net for salesforce

Hi,

I am creating Contact using .net code and it is getting created successfully.

 

But after creating contact I need to do one entry in contact share(you might be wondering why to make entry in contact share when it is being managed by salesforce. well it is just because i wanted to give share all of my contacts created using system administrator's account to be shared by some other users too, so i am creating one more entry pertaining to other users in contactshare)

 

hope the the above senerio is clear to you.

 

well everything works fine but what if something goes wrong in contactshare and it is not able to create row in contactshare ....here i wanted to rollback the record entered in contact also.

 

now the query is how to do that? how to maintain transactions in salesforce.

 

-Anil

 

aalbertaalbert

I see two options.

#1) Store the newly created Contact record Id in your code and if the ContactShare operation fails, delete the Contact. 

#2) Build a custom Apex Web Service that you call from your code, lets call the web service "processContactAndShares()" and you pass the Contact sObject and ContactShare sojbects into that method. That will invoke an apex method that has the savepoint and rollback capabilities.

 

 

AlwaysConfusedAlwaysConfused

 

Aren't all contacts shared anyway?

Or did i miss something?

 

I just kinda figured that that's the point to a CRM system ... collaborated corporate data .... !?!?!?!

aalbertaalbert

Contacts are not always shared. It depends on how you setup your Org-Wide Defaults (private, public read-only, public read/write) amongst other sharing features like Role Hierarchy and Sharing Rules.

apurswaniapurswani

Ok related to same issue I tried to create task and event. now it is instructed to me by the manager, that, if anyone is failed then just rollback others too.

 

now taking this senerio into consideration, is there any way to maintain savepoints and rollback in .net for salesforce.

 

 

I had discussed this with SF Team but not got any reply till date.

 

 

-Anil

 

aalbertaalbert

Please see the two options I suggested earlier. Either build a custom rollback logic in your .net code or build a custom apex web service with force.com.

 

apurswaniapurswani

hey,

thanks for suggestion but could you please tell me how to call apex webservice from .net

aalbertaalbert

You first need to define the apex web service. A brief overview is documented in this article. After you write the apex web service, you can download the WSDL, generate the stub in .NET, and call the new method just like you call any standard Force.com API method.

AlwaysConfusedAlwaysConfused

Fair play ...

Um ... what he said :)

 

aalbert seems to know what he's talking baout here, i'd go that way too :)

dkadordkador

You could always just write an apex trigger on contact, too.  What you're describing seems to be a primary use case for triggers.