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
HelloSanHelloSan 

I want to change the field value from 2016Q2 to 2016Q02 and update this value to the same field,how can this be achieved in apex trigger.

Sagar Wahal 1Sagar Wahal 1

Hi,

If you want to update a field value on an already existing record use the following code snippet:

trigger Trigger_Name on Object_Name(before update) {
    
    if(Trigger.isbefore && Trigger.isUpdate){
        for(Object_Name objInstance : trigger.new)
            if(objInstance.Field_Name__c == '2016Q2')
                objInstance.Field_Name__c = '2016Q02';
    }

}

Note: Above code snippet will be fired only for the record that is being updated.

Let me know if you face any issue.

Regards,
Sagar Wahal

HelloSanHelloSan
Hi Sagar thanks for reply. There are some more values of similar type like 2016 Q1,2016 Q3,2016 Q5 and some more. This is can be achieved through regular expression in apex coding.