Field Update in Salesforce Using Apex Trigger

Here in below example I’m updating a custom field “Comment__c” on Account object, based on the Annual Revenue field, using apex trigger.

Sample Code:

trigger AccountTrigger on Account(before Insert, before update){  
    for(Account acc : Trigger.new)   {       
        if(acc.AnnualRevenue > 500000000){       
            acc.Comments__c = 'Highly revenue customer';     
        }            
    }   
}