0

I need to create an auto number field on custom object in packaging org. I'm not able to create it now because it's throwing an error while creating it:

you cant able to create auto number field once its managed

So I created a one number field and incrementing the number by 1 whenever the record gets created through trigger. Here I am getting an issue of duplicate numbers while am creating multiple records in a single transaction, any solution for this?

0

I'm assuming the error message is:

Error: Auto number fields cannot be added to a custom object when the custom object has already been uploaded in a Managed - Released package.

See this option Auto number field cannot be added into managed package object, any walkaround? where a new custom object is added. The reliable auto-number from the new object can be transferred to the existing object via a trigger.

Surprisingly, I can't find an example of a trigger that does the auto-number generation avoiding duplicates programmatically. The key mechanism to achieve that though is Locking Statements, where the trigger can execute a query with for update and so block triggers running at the same time while the increment is done.

| improve this answer | |

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.