You need to sign in to do that
Don't have an account?
Greg Rohman 9
Assistance with 50k record limit in trigger - comparing to existing records
Hello.
I have a business use case where we are looking to generate a unique identifier every time an Account record is created. The identifier needs to follow a specific format, so an autonumber field is not an option in this scenario.
We have a fairly simple bulkified trigger in place to generate this code. Basically, the trigger:
Any suggestions for an approach to this issue? Much appreciated. Thank you.
-Greg
I have a business use case where we are looking to generate a unique identifier every time an Account record is created. The identifier needs to follow a specific format, so an autonumber field is not an option in this scenario.
We have a fairly simple bulkified trigger in place to generate this code. Basically, the trigger:
- Queries all of the existing Account records for their existing unique identifiers (outside of the trigger loop) for comparison
- Then, for each record in Trigger.new:
- Generates a new code in the format we need
- Compares it against all of the existing codes (from the Account query outside the loop)
- If it's unique:
- update the Account in Trigger.new
- Add the code to the full Account query list so it’s included in the next comparison
- If it's not unique, re-generate the code and repeat the process
- If it's unique:
Any suggestions for an approach to this issue? Much appreciated. Thank you.
-Greg
Chcek below similar best practices.
https://salesforce.stackexchange.com/questions/111977/design-practises-against-50-000-row-limit
Thanks,
You would have to change the trigger context to ‘after insert’, create an instance of the batch class and pass the list of Accounts being inserted to the batch class through the constructor.
This batch class would then generate the unique id for the newly created Account in the background, with the capability of processing millions of records.
Here’s a sample class, I’m not sure if it’ll actually work or if it will fit your need but is something to consider.