• itayf
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hello,

 

Is there any way (a supported way or a tricky workaround) to make Salesforce not to rollback changes done in the trigger eventhough the insertion failed?

 

Sometimes I want to fail the insertion (addError on the sObject) but I want other changes done in the trigger to still happen.

 

For example:

trigger triggerName on Contact (before insert) {
    Contact newContact = Trigger.new[0];
    Contact existingContact = [Select FirstName From Contact Where Id = 'someId'];
    existingContact.FirstName = newContact.FirstName;
    update existingContact;
    insert new Account(Name='newAccount');
    newContact.addError('errorName');
}

In this case, when adding a contact, the update of exisitingContact and the insertion of newAccount will be rolled back...

I do want those changes to occur, eventhough I want the newContact not to be inserted.

 

Playning with opt_allOrNone didn't seem to have any effect.

 

Thanks in advance!

Itay

  • March 21, 2012
  • Like
  • 0

Hello,

 

Is there any way (a supported way or a tricky workaround) to make Salesforce not to rollback changes done in the trigger eventhough the insertion failed?

 

Sometimes I want to fail the insertion (addError on the sObject) but I want other changes done in the trigger to still happen.

 

For example:

trigger triggerName on Contact (before insert) {
    Contact newContact = Trigger.new[0];
    Contact existingContact = [Select FirstName From Contact Where Id = 'someId'];
    existingContact.FirstName = newContact.FirstName;
    update existingContact;
    insert new Account(Name='newAccount');
    newContact.addError('errorName');
}

In this case, when adding a contact, the update of exisitingContact and the insertion of newAccount will be rolled back...

I do want those changes to occur, eventhough I want the newContact not to be inserted.

 

Playning with opt_allOrNone didn't seem to have any effect.

 

Thanks in advance!

Itay

  • March 21, 2012
  • Like
  • 0