Imagine the user clicks a standard New button of a custom objects, populates some fields (in a Standard Layout) and then clicks save.

He then is redirected to the View page of this new record, but is many fields and related lists a populates with values and child records from a hidden template inside the app.

This all would be easy if the structure I am going to deserialize would be stand alone and not dependand on a parent record NOT part of the template.

I therefore required the user to manually populate a parent lookup field and the want to do this in the Before or Aftert Insert trigger:

  1. Get the lookup value from the user's record (temporary)
  2. Deserialize the serialized record (real) using the lookup value
  3. Delete the users record

Now my question: How can a trigger cancel inserting the original record and instead insert and redirect to another?

  • Is the deserialized record of the same sObject type as the one being saved initially?
    – Mark Pond
    Commented Jun 10, 2015 at 0:06
  • It is a tree strucure where the Root is a Record of Same Type Commented Jun 10, 2015 at 6:25
  • 2
    Can't be done in a trigger. I think you're going to have to use VF somewhere.
    – Adrian Larson
    Commented Jun 10, 2015 at 14:28
  • @AdrianLarson Any reference where this is documented? Commented Jun 10, 2015 at 14:35
  • @AdrianLarson just add that as answer and I can credit you some points ;-) Commented Jun 12, 2015 at 15:13

1 Answer 1


Records cannot be removed from a trigger context collection, as it is immutable.

You are going to need to implement a VisualForce workaround to get the functonality you desire. You will then want to use this Page to override the New action on your object.

You must log in to answer this question.

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