You need to sign in to do that
Don't have an account?
Incremental Project Number
Hi,
I know it s possible to have incremental fields. But what i would like is for the automatic field to be determined by another field on the page. For example if they select Department A the project field would be DEPA001, and so forth. But if they were to choose Department B from the field the project number would be DEPB001.
I have tried a few things but i cannot get the project number to increase incrementally based upon the department selection.
E.g If someone creates an opportunity for Department A the Project Number is DEPA001, but if someone then creates an opportunity for Department B it gives DEPB002.
What i would ideally like is for the Project Number number to increase incrementally for each Department, not for all of the opportunites as a whole. If someone could let me know if this is possible to achieve and perhaps point me in a helpful direction that would be great.
Many Thanks,
Matt
Matt,
What you are talking about would not be possible with the standard Autonumber field. It could be done through the use of a custom object and apex triggers.
The idea would be:
1. The custom object would have one record per department. There would be a name field, department prefix, and a number field. So the record may be something like:
Name: Department A Number Incrementer
Prefix: DEPA
Number: 1
2. On your object where you want to have the incremental field, you would have a custom field to hold the number. This field should be read only to your users, as it will be set when you create the record and then never touched
3. On the same object as #2 you will want to create a trigger. The trigger will look up the Custom record from #1 based on your determining field on the object in #2. For instance, if you want Record Type A to have a number of DEPA0001 and Record Type B to use DEPB001, Record Type would be your determining field. The trigger would basically query the custom object, grab the current number and the prefix, combine them to add to the new object, and then increment the number field on the record from #1.
This is just a start, and you would have to code to make sure the trigger worked well in bulk, but hopefully it helps.
Jay
I have similar code sample,
It may help you
Class code:
Trigger code
Cheers,
Bala
This code is not for BULK,
you need to modify it for Bulk
Cheers,
Bala