1

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 Jun 10 '15 at 0:06
  • It is a tree strucure where the Root is a Record of Same Type – Robert Sösemann Jun 10 '15 at 6:25
  • 2
    Can't be done in a trigger. I think you're going to have to use VF somewhere. – Adrian Larson Jun 10 '15 at 14:28
  • @AdrianLarson Any reference where this is documented? – Robert Sösemann Jun 10 '15 at 14:35
  • @AdrianLarson just add that as answer and I can credit you some points ;-) – Robert Sösemann Jun 12 '15 at 15:13
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.

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.