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
Adeline MooreAdeline Moore 

Validating a Auto number field?

I have a field in contact card labeled Canis Minor ID number. NOT all Contcts will need a number only Certified teams. How can I generate an auto number for this field? 
Do I create a auto number field?
Do I need to create another field to trigger the auto number field?
What would my Apex code be?
Tejas KardileTejas Kardile
Hi,

You can try below solution:
  • Create 2 custom fields
  • Auto number field - e.g. Name - Count, display {0}, starting number 1
  • Formula field - Text field, Create conditional formula field sample given below 
  • IF( Amount__c >= 100, Count__c , '')
  • Use Display field for rendering
Instead of Amount you can use certified team criteria to achive your result.

If this resolve your issue then mark this solution as best solution.

Thanks,
EldonEldon
Hi Adeline,

First create a custom setting named CustomName__c  with a field name custNum__c. Then click on manage and create one with default value 0 in that field. Then add this trigger to contact object. (assuming your field 'certified__c' is a boolean.)

 
trigger TestCtr on Contact (before insert) {
    
    CustomName__c cus = CustomName__c.getinstance();
	
    for(contact c : trigger.new){
        if(c.Certified__c == True){
            cus.custNum__c++;
            c.CanisMinorID__c = cus.custNum__c;
        }
    }
    
    upsert cus;
	
}

Let me know if you have any issues.

Regards
 
EldonEldon
Hi Adeline,

Please close the thread if it solved your problem.

Regards