3

I'm working on a e-commerce integration and all it does is insert new opportunities with a block of text containing the details of the transaction, which I then parse out and update various fields with.

The problem is, I get an insert from the api on every change of the order status, and I want to prevent duplicate orders. So I'm thinking on a trigger, before insert see if it's an existing order and if so parse out the changes and update the original order..

and then silently prevent the insert.

Is there a way to have a trigger prevent the insertion (ideally without error), yet not roll back the trigger's changes?

  • Does each entry from the e-commerce system have a unique identifier? – Nick Cook Jun 24 '14 at 6:58
  • they have an external system order number, but it's not passing a truly unique record id. Ie Order 23423 will get get 2 inserts once when the order is saved pending and once after payment is completed. (and that order isn't guaranteed) – Simon Jensen Jul 10 '14 at 16:53
4

The better approach in this case is to use Upsert API Call instead of Insert. Trigger are designed to throw exception when there is error and we will not be able to change it.

https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_upsert.htm

  • yeah that would be ideal but unfortunately the inserts are done by a 3rd party. – Simon Jensen Jul 10 '14 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.