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
imishraimishra 

Auto Increment a field

Hi,

 

I have an object, and there is a field called revision no. which i want to increment by itself everytime the particular record is edited.

 

Is it possible to do..???

 

Thanks in Advance.

Best Answer chosen by Admin (Salesforce Developers) 
Madhan Raja MMadhan Raja M

Try this Trigger:

 

trigger RevisionNumber on Object__c (Before Insert,Before Update) {
    for(Object__c ob:Trigger.New)
    {
        if(ob.Revision_No__c==NULL)
        {
            ob.Revision_No__c=1;
        }
        else
        {
            ob.Revision_No__c+=1;
        }
    }
}

 

 

Replace Object__c with your Standard or Custom object.

 

Madhan Raja M

All Answers

Madhan Raja MMadhan Raja M

Hi Imishra,

 

Yes, we can do this by writing a trigger.

 

Madhan Raja M

Madhan Raja MMadhan Raja M

Try this Trigger:

 

trigger RevisionNumber on Object__c (Before Insert,Before Update) {
    for(Object__c ob:Trigger.New)
    {
        if(ob.Revision_No__c==NULL)
        {
            ob.Revision_No__c=1;
        }
        else
        {
            ob.Revision_No__c+=1;
        }
    }
}

 

 

Replace Object__c with your Standard or Custom object.

 

Madhan Raja M

This was selected as the best answer
imishraimishra

Thanks Madhan for your quick reply.

 

The code works fine..