+ Start a Discussion
Amit Singh.ax1042Amit Singh.ax1042 

Can we control AutoNumber Field?

Hi friends,

i Am facing problem with AutoNumber,

i have created object JobApllication(Master) and Review(Child)...

for review i have taken record name as Job Application number (Data Type is Autonumber)...


i have create two application JA1,JA2


in JA1,i have created two review ( R-1 and R-2 (Auto number ))

in JA2,i have created two review (now here i am getting R-3,R-4)...i want that for different-different  job application review should start with R-1


is it possible?


any suggestion how to solve this kind of issue?



AutoNumber field values are assigned sequentially for each record and are unique in records of the same object.

I believe you have to create a trigger to make your requirement meet.

Amit Singh.ax1042Amit Singh.ax1042

could you give me any example ?

How to solve this kind of issue?


source code?


Unfortunately I don't have any codes related to this.

You might be able to get more suggestions or examples in Apex Code Development board than here.

Ankit AroraAnkit Arora

Amit once you make Name field as Auto Number you cannot control the number. But if you make that field Text again and then again to Auto number then it will start from 0000.


Lets say I have object "X" whose Name field is Auto Number. I have created two records 1) 0001 and 2) 0002


Now if I convert the name field to text and again to auto number then it will again start from 0001. But I don't think this will be much useful for you.


Now as far as trigger is concerned you cannot update the Name field when it is Auto number. You can only update the Name field when it is in text.



Ankit Arora

Blog | Facebook | Blog Page

Amit Singh.ax1042Amit Singh.ax1042

Thanks Ankit!!!

but how we can control text field also???


i mean

suppose i have created two object as Job  and Job Task..

their is a master  detail relationship between job(master) and job task (detail)...


and i want that their should not be a repeated value for a job task (for a particular job)..

if i am creating a record for job as Painting and size is the job task...(then there should not be any more reord(Duplicate) named as size for painting job)...

and if i am creating any other record of job named as Finishing,here i should allow to create size for this job too...

how can i control...

i have taken job task name as Text (Record Name)...

i have written a trigger but there i am not able to create any duplicate value for Job Task.


here is my code... is there any need to make modification in my trigger...?


trigger duplicateJobTasks on Job_Task__c (before insert,before update) {
List<Job_Task__c> lstGC = new List<Job_Task__c>();
    for(Job_Task__c g:Trigger.New)
        lstGC=[select id from Job_Task__c where Name =: g.Name];
           for(Job_Task__c g1:lstGC)
               g.Name.addError('Job Task with same Name Exists');
else if(Trigger.IsUPdate)
for (Job_Task__c no : Trigger.new)
              Job_Task__c old = Trigger.oldMap.get(no.id);
              if (no.Name != old.Name)
                 lstGC = [select id from Job_Task__c where Name =: no.Name];
                 if (lstGC.size() > 0) 
                    for(Job_Task__c noOld : lstGC) 
                           no.Name.addError('Job Task with same Name Exists');
           if(lstGC.size() > 0)
       update lstGC;