I've found sequential numbering on Salesforce to be quite challenging, the more complex the requirement, the more challenging it gets. If you can rely on platform features (rather than code) to fulfill your requirement, then I believe you will have a better time of it.
However, based on what you're saying
Our customer number ranges are different for each company we acquire
Leads me to believe that you'll want to add new ranges as and when you acquire new companies, so I don't believe there is a simple 'platform' solution for you (hopefully, someone has a better idea).
Here is a solution I provided to a similar problem, which is far from ideal but seems to work.
- Create a custom object, call it e.g.
Account Sequence Group. This can hold whatever additional information you like, but is essentially just a 'grouping' for each of your company/sequences
- Create another custom object, call it e.g.
Account Sequence Number. Make it a child of both
Account Group Sequence AND
Account. Create an additional
Sequence Number (numeric) field and any additional info you might wish to store. You will need to have something in place (probably a Trigger) to ensure that no duplicates of Company and Sequence Number occur.
- Create a new Rollup Summary field on Account, e.g.
MAX(Sequence Number). This will allow you access to the sequence number from Account.
Structurally at least, this will allow you to maintain a list of sequences 'by company', for example:
Account Sequence #
Account Sequence #
You can then create a formula field on Account to present the sequence number as you wish.
Finally, you will need a Trigger on Account (insert) to create a new
Account Sequence Number whenever a new Account is created. This trigger would simply create a new
Account Sequence Number record, incrementing the sequence by 1 each time. The 'uniqueness' Trigger on
Account Sequence Number would prevent duplicates should any occur.
I have provided this answer in the knowledge that it is far from ideal, but thought it worth presenting for others to scrutinise and also see if there are any better solutions.