function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Javier MaldonadoJavier Maldonado 

Alphanumeric 4 Digits Sequential Suffix Code

The project that I'm working now is to add a suffix 4 digits alphanumeric sequential code, to a part number, the suffix is starting with AAA0 and then AAA1, AAA2 and go on, this suffix it will be the same when the record contains the same attributes and is going to vary every time that part number is new and different to another one, so all part numbers are going to have this suffix as a part of this part number, in that way we can make this part number the same over the all database.
As the first step, I'm trying to avoid creating a bunch of records at this custom object, and my goal would be, generate this suffix every time that I need it, rather than input these suffix at once on this custom object, we are talking about of more than 175000 of records.
My question would be, how can I guarantee the sequentiality of this suffix? is there a way how to do it using a trigger?... I've tried to write some kind of code but I couldn't find the way how to keep the counters updated for the next sequential code.
The below code is creating all sequential 4 digits code an is working fine in AnonymousWindow...
string [] a = new string[] {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
string [] b = new string[] {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
string [] c = new string[] {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
string [] d = new string[] {'0','1','2','3','4','5','6','7','8','9'};
 
for(integer i=0; i<a.size(); i++)
    for(integer j=0; j<b.size(); j++)
    	for(integer k=0; k<c.size(); k++)
    		for(integer l=0; l<d.size(); l++)
    
        		System.debug( a[i] + b[j] + c[k] + d[l]);
				System.debug( 'special==> '+a[1] + b[2] + c[3] + d[4]);
				System.debug( 'Total==> '+a.size()*b.size()*c.size()*d.size());
Any idea or suggestion will be welcome...
 
Alain CabonAlain Cabon
Hi,

"the record contains the same attributes": that is the obscure part of the requirement.

The only default "counters" of Salesforce are the auto-number fields but they need a new record for each new value.

You have just a formula probably to create that will convert the value of the auto-number field of the object into "ABC4" (base 24 (x3) + base 10) but for "the record that contains the same attributes" (?). The formula could be impossible and you need a trigger/process.

Otherwise, there is just an object counters__c with fields countrer1__c, counter2__c (trivial) but the problem is the combination of the same attributes once again.