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
Phuc Nguyen 18Phuc Nguyen 18 

Auto increment custom alpha numeric field

Hello ALl,
trying to determine if I cna create an alpha numeric field via a formula or if it need sot be done in apex.
So what I am looking at is if the record type is 'Site' then the field needs to be 'S_(postalcode value on record)_incremented number
ex. S_14547_1
Next record with type site and postal code 45447 woueld be
S_45447_2

Thanks,
P
Best Answer chosen by Phuc Nguyen 18
ANUTEJANUTEJ (Salesforce Developers) 
Hi Phuc,

I think this could be done using a trigger before insert that could update the value and then add the record to a list and then insert them.

Let me know if it helps.

Regards,
Anutej

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Phuc,

I think this could be done using a trigger before insert that could update the value and then add the record to a list and then insert them.

Let me know if it helps.

Regards,
Anutej
This was selected as the best answer
Andres MagallanesAndres Magallanes
Hi!
You could create an auto-number field and then a formula field that concatenates "S_(postalcode value on record)_" with the auto-number field value.
Phuc Nguyen 18Phuc Nguyen 18
Thank you for the reply.  The issue is that for every PArent record, the child record should increment from 1 until ....
So parent A with NAme test has 2 child records and their values should be test_1 and  test_2
Parent B with name tester has 3 child records so the child record names would tester_1 tester _2 Tester_3
 
ANUTEJANUTEJ (Salesforce Developers) 
So as you have mentioned you need to update the child records you could use a trigger so that whenever you insert a new record you can have a field to update the number of child records and then in the child record names you can continue to update the value at the end of the name before inserting it into the system. In case if there are no child records you can make sure that the starting number is 1.

If it were to be a simple increase in the record serial value as mentioned by other community members you could use an auto number but as you have stated you would like to have a serial number for child records I think you will have to create a trigger for this implementation.

I hope this helps.