[SalesForce] Update custom object after insert trigger

I have created a trigger for a custom object for the event "After Insert" only. When running the test for this trigger the test fails with the following error:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Assign_Serial_To_Software: execution of AfterInsert

Now, inside the trigger there is an update statement (the entire reason for the trigger in the first place).

  1. Is the error caused by the update statement? (It looks like it is)
  2. If so is there anyway to make the object update itself after insert?

Best Answer

You can not use an after update trigger to update the same object again. This could potentially create an infinite trigger loop.

Try switching to a before update trigger to make the required change.