I've a custom auto case-number field for one of my case record type (Quality Report). Every time a new case is created, the auto case number is generated (ex: QR-1287). However, the auto number field is generated even when a case is created in other record types (QR-1288, QR-1289....) . How do I avoid it? I want the auto case number field to update only on a single case record type, the case number should QR-1288 only if the record-type is of Quality Report. Please help.


Autonumber field in SF is the same auto number field you get in the Traditional Database (Oracle,MySQL etc) . That being said as its handled by the Internal Database and not the SF implementation there is no way one can change this behavior.

You can do a workaround,

  1. Make the name field as Text instead of autonumber
  2. Create a new Autonumber field you want
  3. Create a workflow rule, on created that checks the record type and then updates the name of the record using the autonumber field present on the record.
  • Hey Pranay, Thanks for the reply. If I use the above WFR, Would I be able to fire the auto-number only for specific record type then? – Shashank N Sep 17 '18 at 21:40
  • Yes you can add condition in WF rule that will allow you to fire on when certain conditions are met. – Pranay Jaiswal Sep 17 '18 at 21:47

I suggest code-based handling for the above problem,

In the before Insert section of trigger: Use two variables:- (a) recordTypeId and (b) count

Steps:- String recordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get(*-YOUR Record Type Label- *).getRecordTypeId();

integer count = database.countQuery('SELECT count() FROM Case WHERE RecordTypeId =: recordTypeId');

Now iterate on the new list: for(Case caseObj : Trigger.New){ if(caseObj.RecordTypeId == recordTypeId){ count = count + 1; caseObj.text field = 'your prefix- '+String.valueOf(count); } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.