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
FraidyFraidy 

Auto Number

Is there any way that I can generate automatic numbering for only some of my oppurtunities that meet a ceratin criteria? I am trying to generate reciept numbers, but not all of my Oppurtunities are eligable for it...
Thank you!
jpizzalajpizzala
You could create an autonumber field that is hidden from the page layout. This will provide you with a number when you need it. Then, create a formula field that determines whether or not the Opportunity meets the criteria (as long as this information is accessible via formula fields). If the criteria passes, then display the number from the hidden autonumber field. If the criteria fails, then don't display anything.

HTH
LSKLSK
But suppose you don't want the number auto-assigned to every record - even it's hidden - I have the same issue - I only want to generate a # for contract if it's no longer in a Draft status. What code or technique would be used to create the unique code - so that all active contracts are in numerical order - with no "holes" in the list - which is different from the auto-generated number automatically assigned to every contract - regardless of whether I want this to happen or not.
 
If a draft contract never gets beyond draft - I will have wasted an auto-generated number - and the accouting dept will think the contract is "lost" when in fact it never existed.
 
LSK
JPSeaburyJPSeabury
You could do this with Apex. 
 
1.) Set up a custom field on a dummy account (or some other object) to act as a counter
2.) Create an apex trigger on the Opportunity record that fires whenever an opportunity is created / modified
3.) In the Apex function, verifty that the opportunity matches your auto-number criteria.  If it does, query the database to get the current counter, update it by one, then store that value into your Opportunity auto number field.
 
If you're not comfortable with writing Apex, I'm a mercenary developer for hire.  =)