I thought I had it

I thought I had it

I've amended a code from an expert on here as need similar functionality in a different form.  It sort of works but I only get 1 digit and if error when I change it to "BB01".

The new code is

last_back_box_record = back_box [back_box_site = input.back_box_site] sort by back_box_reference desc;
if (last_back_box_record.ID  =  null)
{
input.back_box_reference="01";
}
else
{
input.back_box_reference=((last_back_box_record.back_box_reference.toLong()  +  1)).toString();
}

I need to prefix all entries with "BB" and for the number format to remain 2digit i.e. ""BB01" to "BB99"